I think the answer to this problem might be some sort of variant of the uniq
function that allows you to count the number of times each line appears in a file:
sort file.txt | uniq -c
The problem for me is that I have used this uniq
function to generate a line count, and because I am merging the output with other files, I end up with duplicate lines in the file that need further rationalisation.
For example, with the original uniq
line count at the beginning of each line:
34 banana
23 apple
48 grapefruit
23 banana
12 apple
So what I need to get to is:
57 banana
35 apple
48 grapefruit
Is there some function that will SUM
on the first field, in all cases where the remaining field(s) are identical?