Arrange output of a command

Hi,

I am using a command :-

 ps -auxwww 2> /dev/null | awk 'match ($0, GIN:[^ ]*/) {print substr($0, RSTART+3, RLENGTH-3)}' | sort |  grep -v -F '[^' | uniq 

which gives output as

   
3 aruau
5 asun
4 cgan
      

Now I need a command which gives me something like this :-

   
3 aruau
5 asun
4 cgan
Total 12
      

Hello Raj999,

As you haven't showed us the complete sample input of ps -auxwww . So following may help you in same though we could make it more simpler within single awk etc.

Your_previous_command(which I haven't tested/tried) | awk '{SUM+=$1;print} END{print "Total " SUM}'

Please let us know if you have any queries with complete sample inputs and output of ps -auxwww .

Thanks,
R. Singh

1 Like

Your match can't possibly work as the regex is not correctly delimited. And, in your output, the colon is missing that the substr should select due to RLENGTH+3 (instead if e.g. 4).

With some assumptions from my part, try

ps -auxwww 2> /dev/null | awk 'match ($0, /GIN:[^ ]*/) {C[substr($0, RSTART+3, RLENGTH-3)]++; SUM++} END {for (i in C) print C, i; print "Total:", SUM}'