0

I need your help to formatting my data. I have a data like below

Ver1
12 45
Ver2
134 23
Ver3
2345 980
ver4
21 1
ver36
213141222 22
....
...etc

I need my data like the below format

ver1  12  45
ver2  134 23
ver3  2345 980
ver4  21  1
etc.....

Also i want the total count of col 2 and 3 at the end of the output. Im not sure the scripts, if you provide simple script (May AWK can, but not sure).if possible please share the detailed answer to learn and understand.

fedorqui
  • 275,237
  • 103
  • 548
  • 598

1 Answers1

0
$ awk 'NR%2{printf $0" ";next;}
       {col1+=$1; col2+=$2} 1;
       END{print "TOTAL col1="col1, "col2="col2}' file
Ver1 12 45
Ver2 134 23
Ver3 2345 980
ver4 21 1
ver36 213141222 22
TOTAL col1=213143734 col2=1071

It merges every two lines as solved by Kent. It also sums the 1st and 2nd column into col1 and col2 vars. Finally, it prints the value in the END {} block.

Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598