Sign in to follow this  
Followers 0
dtilley

Bottom Up File Searching

3 posts in this topic

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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0