Created
October 23, 2011 03:00
-
-
Save bkamapantula/1306799 to your computer and use it in GitHub Desktop.
Reading file with two columns in TCL - Day 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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