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

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

问题描述

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

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

推荐答案

假设每一行有一个数字:

Assuming there is one number per line:

sort <file> | uniq -c

您也可以在 GNU 版本中使用更详细的 --count 标志,例如在 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天全站免登陆