Jump to content
Sign in to follow this  
Clever1mba

text find in log file

Recommended Posts

hello

is there any way to find text and words in .txt file

i have modem log file in system folder

now log file have text "connected at 56000bps"

how to search "connected at 56000bps" in text file and promote user

connected at 56000bps

any solution help a lot

Edited by asimzameer

Share this post


Link to post
Share on other sites

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

Dim $Source = ""

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $Source = $Source & $line
Wend

FileClose($file)

If (StringInStr($Source, "connected at 56000bps"))
 Then
;text is there
Else
;it isn't
EndIf

J


If I am too verbose, just say so. You don't need to run on and on.

Share this post


Link to post
Share on other sites

How about...

$FileName = "something.txt"
$file = FileOpen($FileName, 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$Source = FileRead($FileName,FileGetSize($FileName))

FileClose($file)

If StringInStr($Source, "connected at 56000bps") Then
 ;text is there
Else
 ;it isn't
EndIf

I used J's example above but shortend it abit. Actaully I think you can just do this...

$FileName = "something.txt"

$Source = FileRead($FileName,FileGetSize($FileName))

If StringInStr($Source, "connected at 56000bps") Then
 ;text is there
Else
 ;it isn't
EndIf
Edited by Burrup

qq

Share this post


Link to post
Share on other sites

And with a function :

Func _iFunctionIfStringFound()
    MsgBox(0 + 64, "Info", "String found", 10)
    Exit
EndFunc

Func _iFunctionIfStringNotFound()
    MsgBox(0 + 64, "Info", "String not found", 10)
    Exit
EndFunc

Func _FindStringInTextfile($iFile, $iString, $iFunctionIfStringFound, $iFunctionIfStringNotFound)
    $FileName = $iFile
    $Source = FileRead($FileName,FileGetSize($FileName))
    If StringInStr($Source, $iString) Then
        Call($iFunctionIfStringFound)
    Else
        Call($iFunctionIfStringNotFound)
    EndIf
EndFunc

_FindStringInTextfile("test.txt", "Xavier", "_iFunctionIfStringFound", "_iFunctionIfStringNotFound")

In the Text file :

Pauline
Raphaelle
CĂ©line
Mariane

==> Give : not found

Gniark

:(


----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites

If I understand you, just search for "date:" instead of "connected at 56000bps", get the position of "date:", trim off that bit, then StringLeft($Source, 8) will give you the date part.

pseudocode:

While STringLen($Source) > $MinimumUsabelStringLen

$PosOfDate = StringinStr($Source, "date:")

$Source = StringTrimLeft($Source, $PosOfDate + StringLen("date:") - 1)

$DateValue = StringLeft($Source, StringLen("xx/xx/xx"))

$Source = StringTrimLeft($Source, "trim some more off")

Wend

J


If I am too verbose, just say so. You don't need to run on and on.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...