I have a text file like below.
mark 10 20 30
lawrence 40 22 60
mark 11 12 13
mike 15 16 17
lawrence 21 22 23
mike 31 32 33
mike 41 42 47
I want to process it and produce output to conform to these conditions:
- One line for each unique name (first column). So, for the above example, there should be three output lines; one each for "mark", "lawrence" and "mike".
- Output looks superficially like the input:
- Four columns.
- First column of the output is name (first column of the input).
- Second, third and fourth columns are integers.
- The second column is the number of occurrences of the name in the first column.
- The third column is the number of occurrences of the name in the first column with a value of 20 in the third column of the input.
- The fourth column is the number of occurrences of the name in the first column with a value of 22 in the third column of the input.
Expected output:
mark 2 1 0
mike 3 0 0
lawrence 2 0 2
I've written
... | awk '{ c[$1]++ } END { for (name in c) print name, c[name] }'
My code only outputs
mark 2
mike 3
lawrence 2