Sign in to follow this  
Followers 0
AvN

Readline txt file, read the last line

8 posts in this topic

Hi, I am new to Autoit. I have to open a txt file where I have data, read the last line; and in the last line read the element of column 6.

$file= FileOpen ("C:Test.txt",0)

If $file = -1 Then

Beep(500, 700)

MsgBox(16, "Error", "Unable to open file.")

Exit

EndIf

$last_line = FileReadLine ($file, -1)

MsgBox (0,"Finish reading", $last_line, 1)

Sleep (200)

From here it gives me the last line where I have columns and rows, so I have to extract the data in column 6.

How I do it. I tried to open the file with excel, but as you can imagine the last line of excel is always empty...

Your help will be appreciated.

AvN

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

please post a sample how your last line could look like.... how are the columns seperated...

Edited by andygo

Share this post


Link to post
Share on other sites

Hi, I am new to Autoit. I have to open a txt file where I have data, read the last line; and in the last line read the element of column 6.

$file= FileOpen ("C:Test.txt",0)

If $file = -1 Then

Beep(500, 700)

MsgBox(16, "Error", "Unable to open file.")

Exit

EndIf

$last_line = FileReadLine ($file, -1)

MsgBox (0,"Finish reading", $last_line, 1)

Sleep (200)

From here it gives me the last line where I have columns and rows, so I have to extract the data in column 6.

How I do it. I tried to open the file with excel, but as you can imagine the last line of excel is always empty...

Your help will be appreciated.

AvN

I think you can do it using StringSplit function by specifying delimiters as space or tab.

[size="4"][font="Arial Narrow"][font="Garamond"]Attitude is a little thing that makes a big difference[/font][/font][/size][indent][/indent]

Share this post


Link to post
Share on other sites

please post a sample how your last line could look like.... how are the columns seperated...

Here is how the last line look like (exactly):

18:23:00 -39.0 -39.2 -38.4 -38.8 -39.2 -39 -41

So the question is from this line, how can I make the script to read just the data in colum 6 (which is-39.2). the first column is the time.

This is easily done in Autohotkey by using A-index and A-Loopfield, but I can't see how to doit in Autoit.

Thank you for your help.

Share this post


Link to post
Share on other sites

$avParts = StringSplit($sLine, " ")
ConsoleWrite("Col 6 = " & $avParts[6] & @LF)

Dog ate your help file?

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$avParts = StringSplit($sLine, " ")
ConsoleWrite("Col 6 = " & $avParts[6] & @LF)

Dog ate your help file?

:D

Hi I tried $avParts = StringSplit($sLine, " "), it is not accepting " " but it is accepting "" (without space). But again in this case it reading just 1 character at a time. for eg. $avParts[6]is ":". So it is starting at 18:23:00, the 6th character here is ":"

But I want it to read a value for eg. -39.2 (at once).

I am trying to open the file with excel and real cells, but how to get the last line in excel. The difficulty is that my data may stop at line 200 of excel sheet but the same sheet may have 2000 lines. How to make the script stop reading where at the last line of my data and not at the last line of excel itself?

More help needed.

Edited by AvN

Share this post


Link to post
Share on other sites

Hi I tried $avParts = StringSplit($sLine, " "), it is not accepting " " but it is accepting "" (without space). But again in this case it reading just 1 character at a time. for eg. $avParts[6]is ":". So it is starting at 18:23:00, the 6th character here is ":"

But I want it to read a value for eg. -39.2 (at once).

More help needed.

Back to the help file! :D

The second parameter of StringSplit() is the delimiter. It looked to me like a space was the delimiter. If not, replace it with the correct delimiter (i.e. "," or @TAB). If you pass a null delimiter(i.e. "") it splits out every character, exactly as the help file says.

StringRegExp() could also split on any white space character, but you don't sound like you're ready to go there yet.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Back to the help file! :D

The second parameter of StringSplit() is the delimiter. It looked to me like a space was the delimiter. If not, replace it with the correct delimiter (i.e. "," or @TAB). If you pass a null delimiter(i.e. "") it splits out every character, exactly as the help file says.

StringRegExp() could also split on any white space character, but you don't sound like you're ready to go there yet.

:D

Thanks a lot. @TAB works. You are the man.

Edited by AvN

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