Hi everyone,

I have a text file which looks like this:

( 3,3,0 )       0.9984104       0.000503
( 3,3,1 )       1.000613        0.000484
( 3,3,2 )       1.001192        0.000571
( 3,3,3 )       1.002418        0.00063
( 3,3,4 )       1.003345        0.000583
( 3,3,5 )       1.000215        0.000512
( 3,3,6 )       1.000911        0.000537
( 3,3,7 )       0.9983607       0.000423

I want to change it to the following form.

0       0.9984104       0.000503   
1       1.000613        0.000484   
2       1.001192        0.000571   
3       1.002418        0.00063        
4       1.003345        0.000583        
5       1.000215        0.000512        
6       1.000911        0.000537        
7       0.9983607       0.000423

There is one way that came to my mind and it was replacing each (3,3,i) with i using sed command but I believe that it is not the most intelligent way of doing it. Can anyone explain to me how to solve this problem or give me some links that can help me?

Edited 5 Years Ago by SakuraPink: n/a

sed would be perfect for this. You could also use cut -c if all the tuple-numbers are one digit, or cut -f twice: Once with -d ',' and once with -d ')'

awk '{split($0, a, ","); sub(/\)/,"",a[3]); print a[3]}' source.file > result.file

Or

sed 's!( [0-9],[0-9],\([0-9]\) )!\1!' source.file > result.file
This question has already been answered. Start a new discussion instead.