Jump to content

getting a number out of a txt file


ferris
 Share

Recommended Posts

Hi all,

i am totally a newby at writing programs but autoit is quiet easy, but i can not figure out how to do the following:

if have a txt file generated by our building management system (bms) for our cooling system, looks like this:

12-12-2004   sunday   12:45:00    12.1234
12-12-2004   sunday   13:00:00    11.4567
12-12-2004   sunday   13:15:00    10.2398

now this file is bigger then the three lines you see here.

what i need is the number from the last line, in this case 10.2398.

this most be the output from the autoit program so i can use it in the cacti program (mrtg, thats a graphical tool), cacti uses just a number and can run the autoit prog every time to get this number, because the txt file gets update every 15 minutes.

well a big story but i just need that one number out of the txt file every time i run it, can anyone help me?

i used normally cat and awk commands under unix but i need it under windows.

thanks.

Link to comment
Share on other sites

well to read the first line in a file, with filereadline, its 1.

i dont know about the last line but

if you know the specific line, you can read that

im assuming your text file will be varying sizes though, and the last line number will change.

too bad theres not a way to read the lines in a file... like filegetsize

or is there???

fileappend works to add to the end of a file, but what to read it?

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

ok tried it out but get a fault message:

I:\chiller002-in.au3 (13) : ==> Unbalanced brackets in exp[b][/b]ression.: 
$aTemp = StringSplit(StringStripWS($AllTextArray[$i],7)," ")) 
$aTemp = ^ ERROR

if i delete the last bracket i get this error:

I:\chiller002-in.au3 (14) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: 
$AllTextArray[$i] = $aTemp[4] 
$AllTextArray[$i] = ^ ERROR

whats wrong?

by the way this is how txt file really looks like except there many more lines:

Thursday, December 02, 2004 11:45:00 PM 9.5368
Friday, December 03, 2004 12:00:00 AM   9.5368
Friday, December 03, 2004 12:15:00 AM   9.2584
Friday, December 03, 2004 12:30:00 AM   9.1192
Friday, December 03, 2004 12:45:00 AM   9.3048
Friday, December 03, 2004 01:00:00 AM   9.0728
Friday, December 03, 2004 01:15:00 AM   9.0264
Friday, December 03, 2004 01:30:00 AM   9.0264
Friday, December 03, 2004 01:45:00 AM   8.9336
Friday, December 03, 2004 02:00:00 AM   8.8872
Friday, December 03, 2004 02:15:00 AM   8.7480
Friday, December 03, 2004 02:30:00 AM   8.8408
Friday, December 03, 2004 02:45:00 AM   8.6552
Friday, December 03, 2004 03:00:00 AM   8.5624
Friday, December 03, 2004 03:15:00 AM   8.7480
Friday, December 03, 2004 03:30:00 AM   8.5624
Friday, December 03, 2004 03:45:00 AM   8.5624
Friday, December 03, 2004 04:00:00 AM   8.7016
Edited by ferris
Link to comment
Share on other sites

it looks like your number will be in $atemp[7]

but to always get the last field you could use $atemp[$atemp[0]]

Friday, December 03, 2004 12:45:00 AM 9.3048

fix the extra brackect problem (you dont need it )

it looks like you are trying to split an empty string ($AllTextArray[$i] is empty)

$aTemp = StringSplit(StringStripWS($AllTextArray[$i],7)," ")

if there are blank lines in your text file; that would do it. The end of file would do it too.

this is from the help file:

$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

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

$lastline = $line ;just save the lastline

Wend

FileClose($file)

$aTemp = StringSplit(StringStripWS($lastline,7)," ")

;$atemp[$atemp[0]] ;this variable has the number on the last line

you could always install GAWK under windows and all your old scripts will work

perfectly ( I use gawk :idiot: )

If JESUS,LOHIM,ABBA,BISHNU,YAHE, is your homeboy it is OK but dont

post your likes or dislikes on this board KEEP IT TO YOURSELF SPECIALLY

IF PEOPLE GET OFFENDED BY YOUR COMMENTS

AUTOIT IS MY HOMEBOY

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...