I need to count the values in 2nd column from the output of some command. However, the challenge is I need to consider only those lines which comes after a line containing specific patter. For example:
output of a command (ptree) -
1234 /bin/user/puc/loc 3342 /bin/user/123/loc 7783 sup 1234 abc AAA1 BBB1 CCC1 D444 0909 abc xx11 sd11 lk23 3484 8383 cur uh9u 38tt kj33 sd99 3030 zzz qq11 11ii 39ii ij33 0101 sup kk88 sis8 88si mm92 1020 zz0 98df cv99 kids 8dhd 1111 sup 9ike 39ei 93je 39de
I need to find the first occurrence of sup (which is in 3rd line) and want to have a count of all the values(grouping the similar values) in 2nd column(bold marked) after 3rd line. The number of lines before the first occurrence of 'sup' is not fixed, it may vary from time to time(so can not hard code it to 3).
The output should be like this -
abc 2 cur 1 zzz 1 sup 2 zz0 1
Can someone suggest the optimal way to do this?