Jump to content

Recommended Posts

Posted

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

Posted

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)

NEWHeader1.png

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...