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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit file contents

Status
Not open for further replies.

andremincos

Technical User
Aug 15, 2014
3
ID
Hi everybody,

Can anyone help me to fix my TCL script as below;

##########################################
while { [ gets $open_file line ] != -1 } {
set linerows [join $line ", "]
puts $out_file $strings$linerows
}
##########################################

The questions is;
1. Replace space become delimiter ", " (done)
1. Put numbers into column A
2. How to move the original data for
- column A move to column E
- column E become column F

The original data as follow;

C1010184 1.421 -1.865 16.580 DEFAULT
C1010185 0.158 -3.112 16.453 DEFAULT
C1010186 -0.111 -2.139 16.642 DEFAULT
C1010187 1.175 -2.241 16.339 DEFAULT
C1010188 0.203 -2.778 16.520 DEFAULT
C1010189 1.343 -4.008 16.279 DEFAULT
C1010190 -0.063 -1.819 16.698 DEFAULT
C1010191 0.588 -2.531 16.340 DEFAULT
C1010192 1.086 -3.597 16.353 DEFAULT
C1010193 0.181 -1.676 16.715 DEFAULT
C1010194 1.943 -3.280 16.330 DEFAULT
C1010195 0.299 -2.095 16.643 DEFAULT
C1010196 1.604 -1.797 16.565 DEFAULT
C1010197 -0.048 -2.231 16.626 DEFAULT

I wish the resulted as below;

1, 1.421, -1.865, 16.58, C1010184, DEFAULT
2, 0.158, -3.112, 16.453, C1010185, DEFAULT
3, -0.111, -2.139, 16.642, C1010186, DEFAULT
4, 1.175, -2.241, 16.339, C1010187, DEFAULT
5, 0.203, -2.778, 16.52, C1010188, DEFAULT
6, 1.343, -4.008, 16.279, C1010189, DEFAULT
7, -0.063, -1.819, 16.698, C1010190, DEFAULT
8, 0.588, -2.531, 16.34, C1010191, DEFAULT
9, 1.086, -3.597, 16.353, C1010192, DEFAULT
10, 0.181, -1.676, 16.715, C1010193, DEFAULT
11, 1.943, -3.28, 16.33, C1010194, DEFAULT
12, 0.299, -2.095, 16.643, C1010195, DEFAULT
13, 1.604, -1.797, 16.565, C1010196, DEFAULT
14, -0.048, -2.231, 16.626, C1010197, DEFAULT

Thanks in advance

Regards,
Andre
 
Looks to me as if you can add a count for the line numbers, treat the line as a list so pick each item needed with lindex, then reassemble the line in the right order and output the result.

Andrew
 

fdservices's explanation transformed into code:

Code:
set i 1
while { [ gets $open_file line ] != -1 } {
  puts $out_file "$i, [lindex $line 1], [lindex $line 2], [lindex $line 3], [lindex $line 0], [lindex $line 4]"
  incr i
}

thacoda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top