Clubiing two lines into one using AWK -


i have file following format

 time number val   x    1     y   x    1     y      1     z   b    1     m   b    2     m 

i want club lines same value, final file should this

 time number val   x    2     y      1     z   b    3     m 

how using awk?

you can use awk's associative array:

awk 'nr==1{print $0} nr!=1{a[$1]+=$2; b[$1]=$3;} \  end{ ( in a)  print i, a[i], b[i]}' file 

for sample input, prints:

time number val x 2 y 1 z b 3 m 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -