I am trying to rearrange the columns of below file
input.txt,
Contents of this file:
Name Location Purpose
---------------------------------------------
Andy US Business1
bob UK Business2
output_obtained
Name Purpose Location
---------------------------------------------
Andy Business1 US
bob Business2 UK
Expected_output
Name Purpose Location
---------------------------------------------
Andy Business1 US
bob Business2 UK
TCL file:
set fh [open input.txt r]
set fp [open output.txt w]
while {[gets $fh line]>=0} {
if {[regexp "^-" $line]} {
puts $fp $lin
} else {
puts $fp "[lindex $line 0]\t[lindex $line 2]\t[lindex $line 1]"
}
}
close $fh
close $fp
I cannot understand why the tab is interpreted differently on the last row