Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在 UNIX shell (OS X) 中进行一些数据处理。
在使用uniq -c并进行了一些基于查找的进一步处理之后,我重新对数据进行了排序,并且需要再使用uniq -c一次,但请记住先前计数的结果(例如计数)。
uniq -c
例如,如果输入数据是这样的:
36351 | 3 36351 | 2 36351 | 13 2914 | 1 2914 | 2
那么输出应该是这样的:
36351 | 18 2914 | 3
(字段的顺序并不重要。)
我如何在 shell 中做到这一点?
我不知道uniq如何完成这项工作,但使用 awk 非常简单:
uniq
{ c[$1] += $3; } END { for (s in c) printf("%s | %s\n", s, c[s]); }