Jump to content

read words in text file


Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...