查找文件中的重复行并计算每行重复多少次? [英] Find duplicate lines in a file and count how many time each line was duplicated?

查看:173
本文介绍了查找文件中的重复行并计算每行重复多少次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有类似以下文件的文件:

Suppose I have a file similar to the following:

123 
123 
234 
234 
123 
345

我想要多少次'123'被复制,'234'被复制多少次等等。
所以理想情况下,输出将是:

I would like to find how many times '123' was duplicated, how many times '234' was duplicated, etc. So ideally, the output would be like:

123  3 
234  2 
345  1


推荐答案

假设每行有一个数字:

sort <file> | uniq -c

您可以使用更详细的 - count flag与GNU版本,例如,在Linux上:

You can use the more verbose --count flag too with the GNU version, e.g., on Linux:

sort <file> | uniq --count

这篇关于查找文件中的重复行并计算每行重复多少次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆