Recently in Programming Category

Some tips about awk

| | Comments (0) | TrackBacks (0)

Get the sum of single column
cat a.txt
26.2578125
126.023438
705.6875
6000
7849.08594
15260
35243.3125
88700
378483
Usage: cat a.txt|awk '{(tot+=$1)};END{ print tot}'

Get the sum of each column
cat b.txt
111781888     2564208
111781888     21437296
39077120      21338848
111781888     3138160
111781888     17370216
111781888     9237336
111781888     3484016
111781888     3068568
Usage: cat b.txt| awk '{(tot+=$1) (tot2+=$2)};END{print tot, tot2}'