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
Post a Comment