I am not good with file operations... and am having
a little bit of trouble.
I have bind which triggers and then adds some text
to a file "a" append. So the text is added from the last
line.
I have 2 lines added on my bind trigger.
I want to read these lines with the help of 'get'.
One of my friends suggested 'exec [cat ..blabla' I'm not
good at that.
****
I just need to read the last two lines of a file, everytime they are
added into the file on a trigger. (last and second last lines)
Then I need to set them to two different variables.
And then use them for processing in my script.
****
Also... how can I make it read say a specific line say line 57.
If I want to read a specific line out of the file, how can that be done?
Here is some what I could come up with, after seeing the
File Operations thread in the FAQ section of this forum.
Code: Select all
set myfile "records.dat"
set file [open $myfile "r"]
set data [read -nonewline $file]
close $file
set lines [split $data "\n"]
set lastline [expr [llength $lines] - 1]
set secondlastline [expr [llength $lines] - 2]