Sign in to follow this  
Followers 0
iceberg

read words in text file

12 posts in this topic

hi guys,

appreciate if someone could shed some light on my doubts here....how can i achieve this?

read the 3rd, 5th and 7th words of a text line by line and write it in another tetx file?

thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites



hi guys,

appreciate if someone could shed some light on my doubts here....how can i achieve this?

read the 3rd, 5th and 7th words of a text line by line and write it in another tetx file?

thanks.

Your search feature disabled?

http://www.autoitscript.com/forum/index.ph...ghlite=%2Bwords


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

thanks Zedna....

i was looking at that function....took a while for me to figure out how it works.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

using the following codes i can't seem to read out the 3rd word in each line of the attached text file (log file)

i believe my codes are right but it is just that it doesn't work for this text file particularly.

what can i do? i need to read the 3rd (after :), 7th and the word after "Invalid Comm Type".

thanks.

$Found = "No"
$TxtFile = StringMid(@YEAR & @MON & @MDAY, 3) & ".txt"
$OpenedTxtFile = FileOpen($TxtFile, 0)

If $OpenedTxtFile = -1 Then
    MsgBox(48, "Error!", "File could not be opened. " & @CRLF _
             & "1. Enter a valid path" & @CRLF _
             & "2. Check if the file exists" & @CRLF _
             & "3. Make sure you have access to the file" & @CRLF _
             & "4. Check if the file is not opened by another program/script")
    Exit
EndIf

While 1
    $Line = FileReadLine($OpenedTxtFile)
    If @error Then ExitLoop
    If StringInStr($Line, "invalid comm type") Then
        $Found = "Yes"
        $array = StringSplit($Line, ' ', 1)
        MsgBox(0, "", $array[3])
    EndIf
WEnd

If $Found = "No" Then
    MsgBox(0, "Not found!", "AutoIt could not find the string you were searching for.")
EndIf

thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

http://www.autoitscript.com/forum/index.ph...st&p=382143

if you want the 3 you would use 3-1

So:

$aSRE = StringRegExp...

$ThirdWord = $aSRE[3 - 1]

Etc...

This way you only have to read the file once


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

using the following codes i can't seem to read out the 3rd word in each line of the attached text file (log file)

i believe my codes are right but it is just that it doesn't work for this text file particularly.

what can i do? i need to read the 3rd (after :) , 7th and the word after "Invalid Comm Type".

thanks.

Your TXT file is TAB delimited (not space).

Here is script for parsing:

$Found = "No"
;~ $TxtFile = StringMid(@YEAR & @MON & @MDAY, 3) & ".txt"
$TxtFile = "080606.txt"
$data = FileRead($TxtFile)

If @error Then
    MsgBox(48, "Error!", "File could not be opened. " & @CRLF _
             & "1. Enter a valid path" & @CRLF _
             & "2. Check if the file exists" & @CRLF _
             & "3. Make sure you have access to the file" & @CRLF _
             & "4. Check if the file is not opened by another program/script")
    Exit
EndIf

$data = StringSplit($data, @CRLF, 1) ; get array of lines TXT file

For $i = 1 To $data[0]
    $Line = $data[$i]
    $array = StringSplit($Line, @TAB) ; get array of columns from each line
    If $array[0] > 11 And StringInStr($array[12], "invalid comm type") Then
        $Found = "Yes"
        MsgBox(0, "", $array[3])
    EndIf
Next

If $Found = "No" Then
    MsgBox(0, "Not found!", "AutoIt could not find the string you were searching for.")
EndIf

Share this post


Link to post
Share on other sites

Got it!

Thank you, SmOke_N!

Appreciate your definition of the function. was simple and easy to understand.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

oops...i didnt realise that it was tab delimited.

thanks Zedna!


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

if you had noticed there is a small rectangle is very line of the log file.

i followed SmOke_N codes to remove that but it still didn't work

http://www.autoitscript.com/forum/index.ph...st&p=227407

I even tried StringStripCR....also the same problem.

any other thoughts?

thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

if you had noticed there is a small rectangle is very line of the log file.

i followed SmOke_N codes to remove that but it still didn't work

http://www.autoitscript.com/forum/index.ph...st&p=227407

I even tried StringStripCR....also the same problem.

any other thoughts?

thanks.

C'mon now, you've been here for some time ... What char is it? Copy it, then use MsgBox(64, "Your Mysterious Char", Asc(ClipGet())), now look up the ASCII value in the chart provided for you in your help file.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

apologies :)

thanks for helping yet again.


mouse not found....scroll any mouse to continue.

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