INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Edit file contents

Edit file contents

(OP)
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

RE: Edit file contents

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

RE: Edit file contents


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

RE: Edit file contents

(OP)
Hi there,

Thank a lot. Solved

Cheers!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close