Need help with file reading operations.

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Need help with file reading operations.

Post by awyeah »

Hi,

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] 
Is this correct?? Please help me.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

do a search for seek on this forum :)
Elen sila lúmenn' omentielvo
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Um... okay I'll look into it soon as I get back
after my vacations... 4-5days starting from tommorow.. cya!
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked