Of course, if you've got a really big file, and only need some information from the beginning of the file, you can use the
gets command to read a line at a time, stopping once you've reached the data you need. For example:
Code:
set fd [open $myfile r]
# Skip first 2 lines
gets $fd
gets $fd
# Read and save 3rd line
set count [gets $fd line]
A couple more comments about the code you posted, though. First of all, there's no point to the
format command on the first line. Without any values to format, you're just going to get your format string returned to you, so it's equivalent to:
Code:
set path "/xwinnmr/tcl/xwish_scripts/iu_acqu.txt"
Second, there's no point to the
string range commands in the lines where you're extracting element values with
lindex. You're asking
string range to return all the characters in the element starting with the first one and going all the way to the end. This is always going to be exactly the same as what
lindex is returning, so I don't see why you're doing it. The following accomplishes exactly the same thing:
Code:
set index [lindex $line 0]
set freq1 [lindex $line 1]
set time1 [lindex $line 2]
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting,
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax