ferris Posted December 12, 2004 Share Posted December 12, 2004 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 More sharing options...
t0ddie Posted December 12, 2004 Share Posted December 12, 2004 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 More sharing options...
ferris Posted December 12, 2004 Author Share Posted December 12, 2004 yes i think the txt file varying sizes, buts thats something i can check, but still how to get the last number. Link to comment Share on other sites More sharing options...
ferris Posted December 12, 2004 Author Share Posted December 12, 2004 wauw thats fast!!! thanks!! now i gonna try to understand what you did, and try it out tomorrow at work. Link to comment Share on other sites More sharing options...
ferris Posted December 12, 2004 Author Share Posted December 12, 2004 can i run this in a dosbox?, because i need just the number as an output otherwise cacti cannot handle it. Link to comment Share on other sites More sharing options...
Dalarn Posted December 12, 2004 Share Posted December 12, 2004 (edited) ...a... Edited December 20, 2004 by Dalarn Link to comment Share on other sites More sharing options...
this-is-me Posted December 13, 2004 Share Posted December 13, 2004 You haven't even grasped the concept of what he asked. A dosbox is not a dos box. A dosbox is command.com on win98 and cmd.exe in nt and above. A dos box (in most cases) is a computer running dos. Who else would I be? Link to comment Share on other sites More sharing options...
Dalarn Posted December 13, 2004 Share Posted December 13, 2004 (edited) ...a... Edited December 20, 2004 by Dalarn Link to comment Share on other sites More sharing options...
ferris Posted December 13, 2004 Author Share Posted December 13, 2004 (edited) 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 December 13, 2004 by ferris Link to comment Share on other sites More sharing options...
normeus Posted December 13, 2004 Share Posted December 13, 2004 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 ) 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 http://www.autoitscript.com/autoit3/scite/...iTe4AutoIt3.exe Link to comment Share on other sites More sharing options...
ferris Posted December 13, 2004 Author Share Posted December 13, 2004 Ok that did the trick, i used gawk and my old script and it is working!! Thanks, also from the other people with autoit, i still use it for other things so see you in the future Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now