如何在linux中捕获文本文件中的重复条目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12743800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:30:46 来源:igfitidea点击:
How to catch duplicate entries in text file in linux
提问by Kalin Borisov
Text file:
文本文件:
1 1 2 2 3 3 1 1
I want to catch 1 1
as duplicated
我想捕捉1 1
重复
采纳答案by Lev Levitsky
Your question is not quite clear, but you can filter out duplicate lineswith uniq
:
你的问题不是很清楚,但你可以过滤掉重复的行用uniq
:
sort file.txt | uniq
or simply
或者干脆
sort -u file.txt
(thanks RobEarl)
(感谢 RobEarl)
You can also print only repeating lineswith
您也可以只打印重复行与
sort file.txt | uniq -d
回答by Steve
One way using GNU awk
:
一种使用方式GNU awk
:
awk 'array[1 1
]++' file.txt
Results:
结果:
sort -u file.txt
回答by MLSC
You can use it easily:
您可以轻松使用它:
awk '!x[##代码##]++' file.txt
OR
或者
##代码##