Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading files

Status
Not open for further replies.

geezer34

Technical User
Mar 17, 2004
11
GB
Hi guys

I'm reading a flat file that has the following layout

391 ( 4 391 4 ) ( 40 1 40 ) ( 4\0 0\0 4\0 ) ( 0\4 0\0 0\4 ) OWNED offset 767932
next dim iter 1
392 ( 44 0 4 ) ( 40 1 40 ) ( 0\0 0\0 4\0 ) ( 4\4 0\0 0\4 ) OWNED offset 614700

I want to be able to distinguish when I have the next dim inter 1 line. ANy ideas how to do this???

I thought I coud do something like the following but everyline is always used :-(


gets $inputFile lineBuffer

if { [ scan $lineBuffer "%s %s %s %d" next dim inter one ] == 4 } {
echo "$lineBuffer"
#we have a line we dont need
gets $inputFile lineBuffer
}
Appreciate your pointers on how to overcome ...

Thanks
 
Just had a thought as I hit the submit button...

I can do what I want whith the following:

scan $lineBuffer "%s" next
if { $next == "next" } {
echo "$lineBuffer"
#we have a line we done need
gets $inputFile lineBuffer
}

Is there a better way to do what I want?

Ta
 
I am continually awed by the power of Tcl lists. This is yet another case where what you want is there:

You have already read the file in as a string:
Code:
gets $inputFile lineBuffer
Now, split the string into a list on linefeeds:
Code:
set lbLst [split $lineBuffer /n]
Now, find the indices of all the elements that meet your search criterion:
Code:
set indxLst [lsearch -all $lbLst next dim iter 1
]
Now $indxLst will be a list of all the indices in lbLst where the element equals next dim iter 1

What you do next depends on what you want to happen.


_________________
Bob Rashkin
 
my mistake: next dim iter 1 should obviously be in quotes:
Code:
set indxLst [lsearch -all $lbLst "next dim iter 1"]


_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top