Reputation: 35
I have a file index.txt which contains PC name [say temp[0] etc.] and performance parameter [say 2.3 etc], arranged in tabular fashion as
PC Memory Processor Bus Performance .
i want a tcl file to extract string PC and Performance values only.
Please give me some advice.
Upvotes: 0
Views: 540
Reputation: 246754
You will want the textutil::split
package from tcllib.
package require textutil::split
set fid [open index.txt r]
while {[gets $fid line] != -1} {
lassign [textutil::split::splitx $line] pc memory processor bus performance
puts "$pc $performance"
}
If you don't want to use tcllib, you can do this:
while {[gets $fid line] != -1} {
set words [regexp -all -inline {\S+} $line]
if {[llength $words] == 7} {
puts "[lindex $words 0] [lindex $words 4]"
}
}
Upvotes: 1