bash - Manipulate columns using awk or sed -


i have file rearrange....

input file:

sublat 16 0.04 0.051 32 0.04 0.050 16 0.06 0.055 32 0.06 0.054 c2dotc2 16 0.04 0.464 32 0.04 0.624 16 0.06 0.505  32 0.06 0.743 

output file:

      b    sublat   c2dotc2   0.04   16   0.051    0.464  0.04   32   0.050    0.624       0.06   16   0.055    0.624   0.06   32   0.054    0.743 

how achieve using awk, sed?

this awk script works requirement:

awk 'begin{ofs="\t";h="a\tb"}     nf==1{h=h ofs $0;next}     {x=$2ofs$1;r[x]=!r[x]?$3:r[x]ofs$3}     end{print h;n=asorti(r,d);for(i=1;i<=n;i++)print d[i],r[d[i]]}' file 

test data:

kent$  cat file sublat 16 0.04 0.051 32 0.04 0.050 16 0.06 0.055 32 0.06 0.054 c2dotc2 16 0.04 0.464 32 0.04 0.624 16 0.06 0.505  32 0.06 0.743  kent$  awk 'begin{ofs="\t";h="a\tb"}         nf==1{h=h ofs $0;next}         {x=$2ofs$1;r[x]=!r[x]?$3:r[x]ofs$3}         end{print h;n=asorti(r,d);for(i=1;i<=n;i++)print d[i],r[d[i]]}' file       b       sublat  c2dotc2 0.04    16      0.051   0.464 0.04    32      0.050   0.624 0.06    16      0.055   0.505 0.06    32      0.054   0.743 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -