linux - Transposing specific rows to columns -


i have millions of lines this. want write simple bash script information.

                            name:                 1fj                         ha_rmsds:          -1000.0000                         ha_rmsdh:          -1000.0000                         ha_rmsdm:              0.0000                       grid_score:          -24.958729                  grid_vdw_energy:          -24.958729                   grid_es_energy:            0.000000        internal_energy_repulsive:            5.894002                             name:       zinc103990867                         ha_rmsds:          -1000.0000                         ha_rmsdh:          -1000.0000                         ha_rmsdm:              0.0000                       grid_score:          -22.196136                  grid_vdw_energy:          -17.917459                   grid_es_energy:           -4.278677        internal_energy_repulsive:           14.832469 

i want this;

name            grid_score zinc103990867   -22.196136 1fj             -24.958729 

i have found solution not it.

any highly appreciable.

when have name value mappings in input it's best first create array holding mappings , print values names:

$ cat tst.awk { sub(/:/,"") }  nr==1 { key=$1 } $1==key { prt() } { f[$1] = $2 } end { prt() }  function prt(   i) {     if (nr==1) {         numcols = split(c,cols,/,/)         (i=1; i<=numcols; i++) {             printf "%s%s", cols[i], (i<numcols?ofs:ors)         }     }     else {         (i=1; i<=numcols; i++) {             printf "%s%s", f[cols[i]], (i<numcols?ofs:ors)         }     } } 

.

$ awk -v c='name,grid_score' -f tst.awk file | column -t name           grid_score 1fj            -24.958729 zinc103990867  -22.196136 

.

$ awk -v c='name,grid_score,ha_rmsds,grid_es_energy' -f tst.awk file | column -t name           grid_score  ha_rmsds    grid_es_energy 1fj            -24.958729  -1000.0000  0.000000 zinc103990867  -22.196136  -1000.0000  -4.278677 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -