AGsol Posted January 19, 2009 Posted January 19, 2009 Hi I'm new to the forum and I have read the FAQ but couldn't find an answer. I have the below script which works to certain degree but I can't get it to loop on the $Username? I hope someone can help. CODE $Loop = 1 $Log = FileOpen("c:\test\test.w3c", 0) $input = FileOpen("c:\test\test.txt", 0) $Output = FileOpen("c:\test\isa03.csv", 1) $While 1 $Username = FileReadLine($input) If @error = -1 Then ExitLoop While 1 $Read = FileReadLine($Log, $Loop) If @error = -1 Then ExitLoop If StringInStr($Read, $Username) Then FileWriteLine($Output, $Read ) Else EndIf $Loop = $Loop + 1 WEnd WEnd FileClose($Log) FileClose($input) FileClose($Output)
Andreik Posted January 19, 2009 Posted January 19, 2009 (edited) HiI'm new to the forum and I have read the FAQ but couldn't find an answer. I have the below script which works to certain degree but I can't get it to loop on the $Username? I hope someone can help. CODE $Loop = 1 $Log = FileOpen("c:\test\test.w3c", 0) $input = FileOpen("c:\test\test.txt", 0) $Output = FileOpen("c:\test\isa03.csv", 1) $While 1 $Username = FileReadLine($input) If @error = -1 Then ExitLoop While 1 $Read = FileReadLine($Log, $Loop) If @error = -1 Then ExitLoop If StringInStr($Read, $Username) Then FileWriteLine($Output, $Read ) Else EndIf $Loop = $Loop + 1 WEnd WEnd FileClose($Log) FileClose($input) FileClose($Output)Please explain what you want to do clearly.You want to write in output only if in line that was read from file $input exist line read from $log? Edited January 19, 2009 by Andreik
AGsol Posted January 19, 2009 Author Posted January 19, 2009 Please explain what you want to do clearly.Yeah sorry that was a typo on the code page not on my script it is While 1 not $While.I want to Read a file with a list of usernames a line at a time and then with that username check through another file line by line to output all the lines relevant to that user once finished with that username move on to the next.Thanks for the quick response hope this makes it clear.
tannerli Posted January 19, 2009 Posted January 19, 2009 $users = FileOpen("users.txt", 0) $out = FileOpen("matching lines.txt", 1) While 1 $user = FileReadLine($users) If @error Then ExitLoop $log = FileOpen("file to be checked.txt", 0) While 1 $line = FileReadLine($log) If @error Then ExitLoop If StringInStr($line, $user) Then FileWriteLine($out, $line) EndIf WEnd FileClose($log) WEnd FileClose($users) FileClose($out) this should work, you have to close the logfile everytime you loop through it to reset the filepointer...
AGsol Posted January 19, 2009 Author Posted January 19, 2009 $users = FileOpen("users.txt", 0) $out = FileOpen("matching lines.txt", 1) While 1 $user = FileReadLine($users) If @error Then ExitLoop $log = FileOpen("file to be checked.txt", 0) While 1 $line = FileReadLine($log) If @error Then ExitLoop If StringInStr($line, $user) Then FileWriteLine($out, $line) EndIf WEnd FileClose($log) WEnd FileClose($users) FileClose($out) this should work, you have to close the logfile everytime you loop through it to reset the filepointer... Thanks alot that worked fine.
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