EmptySpace Posted February 27, 2013 Posted February 27, 2013 (edited) Two .txt files: Exmaple of first txt 424242424242:text 3423434322311:text 2133245345344:text 5443322134566:text 65432345322344:text And so on Second txt: user:65432345422344:email:address user:424242424242:emailt:address user:43324567534:email:address And so on So what I want is to find these code dublicates and from 2 lines make only 1 in new txt. For example firstly I check 424242424242:text and compare few hundrets of other file lines till I find 424242424242. When I find output in new txt should be 424242424242:text |empty space or any symbol| user:424242424242:emailt:address. Better would be without that code. And if same code wasnt found then go for 3423434322311:text .... What I already tried. #include <FileConstants.au3> #include <array.au3> Global $hashpw1 = FileOpen("txtfile1.txt", 0) global $hasemail1 = FileOpen("txtfile2.txt", 0) Global $hOutPutFile = FileOpen("output.txt", $FO_OVERWRITE) While 1 $hashpw = FileReadLine($hashpw1) For $i = 1 to 6000 ;Im not sure for this loop. I need to check ALL lines so maybe I should use _FileCountLines() ? $hasemail = FileReadLine($hasemail1) $aSplit1 = StringSplit($hasemail, ":") If StringInStr(StringMid($hashpw,1,32),$aSplit1) Then MsgBox(0,"","found?") FileWriteLine($hOutPutFile,$hashpw&" "&$hasemail) EndIf Next WEnd FileClose($hashpw1) FileClose($hasemail1) FileClose($hOutPutFile) BRAINPAIN! Edited February 27, 2013 by EdgarT
kylomas Posted February 27, 2013 Posted February 27, 2013 EdgarT, This will get you started. Instead of processing the files line by line I am using arrays. See the comments in the code. expandcollapse popup#include <array.au3> ;------------------------------------------------------------------------------------------------------ ; create two test files ;------------------------------------------------------------------------------------------------------ local $str $str &= '424242424242:text' & @crlf $str &= '3423434322311:tex' & @crlf $str &= '2133245345344:text' & @crlf $str &= '5443322134566:text' & @crlf $str &= '65432345322344:text' & @crlf filedelete(@scriptdir & '\file1.txt') filewrite(@scriptdir & '\file1.txt',$str) $str = '' $str &= 'user:65432345422344:email:address' & @crlf $str &= 'user:424242424242:emailt:address' & @crlf $str &= 'user:43324567534:email:address' & @crlf filedelete(@scriptdir & '\file2.txt') filewrite(@scriptdir & '\file2.txt',$str) ;------------------------------------------------------------------------------------------------------ ; read files to arrays, process arrays and write output ;------------------------------------------------------------------------------------------------------ ; read each file into an array local $aFile1 = stringsplit(fileread(@scriptdir & '\file1.txt'),@crlf,3) local $aFile2 = stringsplit(fileread(@scriptdir & '\file2.txt'),@crlf,3) local $atemp ; get each element for the array of file #1 for $1 = 0 to ubound($aFile1) - 1 ; split at the ":" for later compare...the compare value will be in element $atemp[0] $atemp = stringsplit($aFile1[$1],':',2) ;get each element for file #2 for $2 = 0 to ubound($aFile2) - 1 ; now compare each element in file #2 to the value in file number 1 that preceeds the ":" if stringinstr($aFile2[$2], $atemp[0]) > 0 then ; if file #2 element contains the string from file #1 element then write a console message ; here is where you put whatever code you want to process these trings. ConsoleWrite(stringformat('---------------------------------------\n%s\n%s\n',$aFile1[$1],$aFile2[$2]) & @LF) EndIf Next next Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
EmptySpace Posted February 27, 2013 Author Posted February 27, 2013 Thank you! Im just started learning arrays and its little hard..
kylomas Posted February 27, 2013 Posted February 27, 2013 (edited) Read the code piece by piece and make sure you uderstand what it is doing and why. The HELP file is your best friend right now! Good Luck, kylomas edit : In this case just think of the array as a list with each member of the list referenced by position...e.g $aFile1[3] would be the fourth value in the list (arrays start at offset 0). In a for...to... loop the for variable is an incrementing number starting at whatever value you specify. That is why they are useful for iterating an array. Edited February 27, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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