Sign in to follow this  
Followers 0
Qual-IT London

Find

3 posts in this topic

Does anyone have a script that could easily be modified to read a mail server log file

and pick out the email address ABOVE the line that has @workplaceintelligence in it

In this example the bits the script should find are in bold

T 20051213 123231 439857bb MAIL FROM:<qc.rentals@wanadoo.fr> SIZE=4005

T 20051213 123231 439857bb RCPT TO:<info@workplaceintelligence.co.uk>

T 20051213 123231 439857bb MAIL FROM:<bill@barclays.co.uk> SIZE=4005

T 20051213 123231 439857bb RCPT TO:<jon@bluespring.co.uk>

T 20051213 123231 439857bb MAIL FROM:<ram@btinternet.co.uk> SIZE=4005

T 20051213 123231 439857bb RCPT TO:<info@workplaceintelligence.net>

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

maybe

#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

i wrote this ealier today

then use stringbetween.. its in here

http://www.autoitscript.com/forum/index.ph...70&hl=Valuater#

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Lesson 15 from Welcome to Autoit 1-2-3 ( IE.au3 example )

; demonstration to find chracters that change between to standard points
; or just find a string
#include <IE.au3>

#Region --- IE-Builder generated code Start ---

$oIE = _IECreate ()

;------------- User input --------------
_IENavigate ($oIE, "http://www.autoitscript.com/"); web address
$Find = "LZ"; my info shows after this line... or just find this line
$Before = "comp"; my info shows before this line... or set as ""
; ------------ End User input -------------
Sleep(1000)
$body =  _IEBodyReadHTML ($oIE)
$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
FileWrite($sloc, $body)
$sfile = FileOpen($sloc, 0)
$num = 0
While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found   " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = stringbetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is " & $Found & "   ", 5)
        ExitLoop
    EndIf
WEnd

Func stringbetween($str, $start, $end)
    $pos = StringInStr($str, $start)
    If Not @error Then
        $str = StringTrimLeft($str, $pos + StringLen($start) - 1)
        $pos = StringInStr($str, $end)
        If Not @error Then
            $str = StringTrimRight($str, StringLen($str) - $pos + 1)
            Return $str
        EndIf
    EndIf
EndFunc  ;==>stringbetween

#EndRegion --- IE-Builder generated code End ---

just change the top lines

8)


NEWHeader1.png

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