0

I'm using UNIX language to extract my files. I used this command to extract it:

value_1=$(cat tmp.csv | head -1001 | cut -f 3-6 -d','> tmp1.csv)
value_2=$(cat tmp.csv | head -2002 | tail -1001 | cut -f 4-6 -d','> tmp2.csv)
paste -d ',' tmp1.csv tmp2.csv > final.csv

My "tmp.csv" file is :

0   0   0   17.92204    -3.017933   35.14229
1   0   1   18.27151    -3.179997   35.20044
2   0   2   18.22776    -3.566021   34.87167
                      .
                      .
0   1   0   20.89817    -2.37854    66.51003
1   1   1   21.48396    -2.461451   66.48988
2   1   2   21.78348    -2.575202   66.51389

But the result is like this :

0   17.92204    -3.017933   35.14229
    20.89817    -2.37854    66.51003
1   18.27151    -3.179997   35.20044
    21.48396    -2.461451   66.48988
2   18.22776    -3.566021   34.87167
    21.78348    -2.575202   66.51389

I want to make the result like this :

0   17.92204    -3.017933   35.14229    20.89817    -2.37854    66.51003
1   18.27151    -3.179997   35.20044    21.48396    -2.461451   66.48988
2   18.22776    -3.566021   34.87167    21.78348    -2.575202   66.51389

I was wondering if it would be possible to achieve that without manually handling?

  • post a testable fragment of your tmp.csv – RomanPerekhrest Nov 13 '17 at 11:15
  • Thank your for the comment Mr. Roman, I have just added the "tmp.csv" file above – ahmad adilah Nov 14 '17 at 1:55
0

If we can base on the fact that first line has 4 items and second 3, we could do this for example using awk:

$ cat input-file | awk '{if(NF==4){aa=$0} else {print aa" "$0;}}' > output-file
0

Previous output which you mentioned in question I believe that is the output of final.csv

0   17.92204    -3.017933   35.14229
    20.89817    -2.37854    66.51003
1   18.27151    -3.179997   35.20044
    21.48396    -2.461451   66.48988
2   18.22776    -3.566021   34.87167
    21.78348    -2.575202   66.51389

Use this command

cat final.csv | sed "N;s/\n/ /g"

Output

0   17.92204    -3.017933   35.14229     20.89817    -2.37854    66.51003
1   18.27151    -3.179997   35.20044     21.48396    -2.461451   66.48988
2   18.22776    -3.566021   34.87167     21.78348    -2.575202   66.51389

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.