我有一个字符串列表(stdin),如下:
1 pineapples 28 apples 16 oranges 8 apples 2 apples 2 oranges 56 pineapples
是否有一种本地方式(如sort& uniq -c),我可以将它合并并将它们总结为:
38 apples 18 oranges 57 pineapples
比如sort | uniq -c do,但不仅仅是出现次数?
试试这个:
原文链接:https://www.f2er.com/bash/384161.htmlawk '{a[$2] += $1} END{for (i in a) print a[i],i}' < in.txt
38 apples 57 pineapples 18 oranges