dtilley Posted April 13, 2006 Share Posted April 13, 2006 I would like to search a log file from the bottom up to find the latest occurance of a string. I cannot see a way to do this in AutoIt other than to read through the file forwards, searching each line for the string and recording the information needed until the end of file is reached. Is there a better way, is this my best bet, or should I be looking at a solution better suited for my application? Thanks for any advice, DT Link to comment Share on other sites More sharing options...
Valuater Posted April 13, 2006 Share Posted April 13, 2006 this will do the trick #include <File.au3> $File_name = "logfile.txt" $find = "Computer 3" $num = _FileCountLines($File_name) For $x = $num to 1 Step -1 $line = FileReadLine($File_name, $x) If StringInStr($line, $find) Then MsgBox(64, "Found", $find & " on line # " & $x & " ") ; do what you want EndIf Next ***** TESTED OK 8) Link to comment Share on other sites More sharing options...
randallc Posted April 13, 2006 Share Posted April 13, 2006 Hi, I don't know if that is fast on a huge file (1gig etc); you might prefer to wrap "tail.exe" (Google it?) in RunDos command, though I think it specifies how many lines you search through in the call [am I right about the speed issue?] Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
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