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.
我在 linux 机器上的许多 shell 脚本中都使用了“uniq -d -c 文件”,它可以工作。在我的 MAC(安装了开发人员工具的 OS X 10.6.7)上,它似乎不起作用:
$ uniq -d -c testfile.txt usage: uniq [-c | -d | -u] [-i] [-f fields] [-s chars] [input [output]]
如果有人可以检查这一点,那就太好了。
嗯,它就在Usage消息中。[ -c | -d | -u]意味着您可以使用其中一种可能性,而不是两种。
Usage
[ -c | -d | -u]
由于 OSX 基于 BSD,您可以在此处查看,或者感谢 Ignacio,查看更多 Apple 特定的此处。
如果要实现类似的输出,可以使用:
do_your_thing | uniq -c | grep -v '^ *1 '
这将删除所有计数为 1 的合并行。
你可以试试这个 awk解决方案
awk
awk '{a[$0]++}END{for(i in a)if(a[i]>1){ print i ,a[i] } }' file