JonnyQuy Posted January 26, 2018 Posted January 26, 2018 (edited) I have 2 text files containing all the links file 1 contains http://www.link1.com http://www.link2.com http://www.link3.com http://www.link4.com http://www.link5.com file 2 contains http://www.link3.com http://www.link4.com http://www.link5.com http://www.link6.com http://www.link7.com I would like to use _ArrayConcatenate to combine these two files, then use _ArrayUnique to remove the duplicate values. And finally I want to use _ArrayConcatenate (2D) to retrieve the values of file 2 and save it I have learned and do not know how to use it, please help me, I am very thankful Edited January 26, 2018 by JonnyQuy
Gianni Posted January 26, 2018 Posted January 26, 2018 ... something like this should do: #include <File.au3> #include <Array.au3> ; disk files containig links Local $sFilename1 = "links1.txt" Local $sFilename2 = "links2.txt" Local $sNewFile = "Result.txt" ; get content from files to arrays Local $aArray1 = FileReadToArray($sFilename1) Local $aArray2 = FileReadToArray($sFilename2) ; content of $aArray2 is merged into $aArray1 _ArrayConcatenate($aArray1, $aArray2) ; create a new array containing only unique elements $aArray3 = _ArrayUnique($aArray1, 0, 0, 0, 0) _ArrayDisplay($aArray3, "Debug") ; save the content of $aArray3 to a disk file _FileWriteFromArray($sNewFile, $aArray3) JonnyQuy 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
JonnyQuy Posted January 26, 2018 Author Posted January 26, 2018 After the _ArrayUnique I want to split the contents of $ sFilename1 and $ sFilename2 to save the elements of $ sFilename2.
Gianni Posted January 26, 2018 Posted January 26, 2018 .. do you need to retrieve the links that are contained only in File 2 and not also in file 1 ? JonnyQuy 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
JonnyQuy Posted January 26, 2018 Author Posted January 26, 2018 yes i need to get links that are not duplicated in file 2
Gianni Posted January 26, 2018 Posted January 26, 2018 (edited) well, time ago I wrote a function that could be useful to solve your problem something like this should work: expandcollapse popup#include <File.au3> #include <Array.au3> ; disk files containig links Local $sFilename1 = "links1.txt" Local $sFilename2 = "links2.txt" Local $sNewFile = "Result.txt" ; get content from files to arrays Local $aArray1 = FileReadToArray($sFilename1) Local $aArray2 = FileReadToArray($sFilename2) ; create a new 2D array containing elements as following: ; column [0] : elements contained only in file 1 ; column [1] : elements contained only in file 2 ; column [2] : elements contained in both files Local $aArray3 = _Separate($aArray1, $aArray2) _ArrayDisplay($aArray3, "Debug") ; count the number of links found Local $iRows = 0 For $i = 0 To UBound($aArray3) -1 If $aArray3[$i][1] <> "" Then $iRows += 1 Else ExitLoop EndIf Next If $iRows Then ; if there are wanted links ; extract found links Local $aArray4 = _ArrayExtract($aArray3, -1, $iRows - 1, 1, 1) _ArrayDisplay($aArray4, "found links") ; save links to disk file _FileWriteFromArray($sNewFile, $aArray4) Else MsgBox(0, "Debug", "no links found") EndIf Func _Separate(ByRef $in0, ByRef $in1) $in0 = _ArrayUnique($in0, 0, Default, Default, 0) $in1 = _ArrayUnique($in1, 0, Default, Default, 0) Local $z[2] = [UBound($in0), UBound($in1)], $low = 1 * ($z[0] > $z[1]), $aTemp[$z[Not $low]][3], $aOut = $aTemp, $aNdx[3] For $i = 0 To $z[Not $low] - 1 If $i < $z[0] Then $aTemp[$i][0] = $in0[$i] If $i < $z[1] Then $aTemp[$i][1] = $in1[$i] Next For $i = 0 To $z[$low] - 1 $x = _ArrayFindAll($aTemp, $aTemp[$i][$low], 0, 0, 1, 0, Not $low) If Not @error Then ; both For $j = 0 To UBound($x) - 1 $aTemp[$x[$j]][2] = 1 Next $aOut[$aNdx[2]][2] = $aTemp[$i][$low] $aNdx[2] += 1 Else ; only in $low $aOut[$aNdx[$low]][$low] = $aTemp[$i][$low] $aNdx[$low] += 1 EndIf Next For $i = 0 To $z[Not $low] - 1 If $aTemp[$i][2] <> 1 Then $aOut[$aNdx[Not $low]][Not $low] = $aTemp[$i][Not $low] $aNdx[Not $low] += 1 EndIf Next ReDim $aOut[_ArrayMax($aNdx)][3] Return $aOut EndFunc ;==>_Separate Edited January 26, 2018 by Chimp UBound($aArray3) -1 JonnyQuy 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
JonnyQuy Posted January 26, 2018 Author Posted January 26, 2018 Thank you I have found a short but not how to delete the same value Local $filenew = @ScriptDir & "\links1.txt" Local $filesave = @ScriptDir & "\links2.txt" $new = _FileReadToArray($filenew) $save = FileRead($filesave) For $a = 1 To UBound($new) - 1 If StringInStr($save, $new[$a]) = True Then _ArrayDelete($new[$a]) EndIf Next
JonnyQuy Posted January 26, 2018 Author Posted January 26, 2018 Let me try your way maybe it is the best way
Gianni Posted January 26, 2018 Posted January 26, 2018 .... from what I see from the screenshot, all links contained in the links2.txt file are also contained in the links1.txt file, so they are considered "duplicate" and consequently discarded. For what I understud, you need to keep only links that are present in links2.txt but not also in the links1.txt file. .....isn't so? JonnyQuy 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
JonnyQuy Posted January 26, 2018 Author Posted January 26, 2018 I really like this way it works very well, I want to get information from links1 file, _FileWriteFromArray ($ sNewFile, $ aArray4) does not work
Gianni Posted January 26, 2018 Posted January 26, 2018 if you want to keep and save only content of first column (column 0) of the array, the you have to change the "index" in the code so to point to column 0 of the array instead of column 1. for convenience I've changed a bit the code inserting a new variable called $iWantedColum, so you can set that variable to the column you are interested to keep. change this portion of code in the main script. _ArrayDisplay($aArray3, "Debug") Local $iWantedColumn = 0 ; column to keep (0, 1, or 2) ; count the number of links found Local $iRows = 0 For $i = 0 To UBound($aArray3) - 1 If $aArray3[$i][$iWantedColumn] <> "" Then $iRows += 1 Else ExitLoop EndIf Next If $iRows Then ; if there are wanted links ; extract found links Local $aArray4 = _ArrayExtract($aArray3, -1, $iRows - 1, $iWantedColumn, $iWantedColumn) _ArrayDisplay($aArray4, "found links") ; save links to disk file _FileWriteFromArray($sNewFile, $aArray4) Else MsgBox(0, "Debug", "no links found") EndIf JonnyQuy 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
JonnyQuy Posted January 26, 2018 Author Posted January 26, 2018 (edited) I'm new to autoit, your way is very good but beyond my comprehensionI really like this way it works very well, hehehe Edited January 26, 2018 by JonnyQuy
Gianni Posted January 26, 2018 Posted January 26, 2018 You are welcome JonnyQuy 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now