Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
Created October 23, 2011 03:00
Show Gist options
  • Save bkamapantula/1306799 to your computer and use it in GitHub Desktop.
Save bkamapantula/1306799 to your computer and use it in GitHub Desktop.
Reading file with two columns in TCL - Day 2
# First three commands reads the data in to a file variable
set fp [open "2columns.txt" r]
set content [read $fp]
close $fp
# Next two commands reads all rows
set records [split $content "\n"]
set count 0
# Next commands parses each row where two columns are separated by a white-space
foreach rec $records {
set element [split $rec " "]
foreach number $element {
incr count
if { $count % 2 == 1 } {
if {[regexp {[0-9]+} $number col_one]} {
puts "Column one = $col_one"
}
}
if { $count % 2 == 0 } {
if {[regexp {[0-9]+} $number col_two]} {
puts "Column two = $col_two"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment