0

We have below format of data in a txt file.Need to add the count(pid) on the basis of pid. Can we put awk logic .

pid Name count(pid)
4   a       24
5   b       22
4   a       21
3   c       20
5   b       4
3   c       43

Below is the expected result Expected result!

pid Name count(pid)
4   a       45
5   b       26
3   c       63
appi
  • 75
  • 1
  • 3
  • 10
  • Tried this command but it just sums up the columns directly not on conditional basis cat count.txt | awk '{ sum+=$1} END {print sum} – appi May 27 '16 at 08:09
  • 1
    The answer linked by @Kent won't work for multiple columns as keys. Use this instead: `awk 'NR==1{h=$0;next}{a[$1,$2]+=$3}END{print h;for (i in a) {split(i,b,SUBSEP);print b[1],b[2],a[i]}}' file` – user000001 May 27 '16 at 08:12
  • Not working for this case!!! – appi May 27 '16 at 08:36

0 Answers0