使用linux命令"sort -f | uniq -i"一起忽略大小写

Ste*_*3p0 4 linux sorting awk gawk uniq

我试图在两列数据列表中找到唯一且重复的数据.我真的只想比较第1列中的数据.

数据可能如下所示(由制表符分隔):

What are you doing?     Che cosa stai facendo?
WHAT ARE YOU DOING?     Che diavolo stai facendo?
what are you doing?     Qual è il tuo problema amico?
Run Code Online (Sandbox Code Playgroud)

所以我一直在玩弄以下内容:

  1. 排序而不忽略大小写(只是"排序",没有-f选项)给了我更少的重复

    gawk'{FS ="\ t"; 打印$ 1}'EN-IT_Corpus.txt | 排序 | uniq -i -D> dupes

  2. 使用忽略大小写("sort -f")进行排序会给我更多重复

    gawk'{FS ="\ t"; 打印$ 1}'EN-IT_Corpus.txt | sort -f | uniq -i -D> dupes

如果我想找到忽略大小写的重复项,我是否认为#2更准确,因为它首先忽略大小写然后根据排序数据找到重复项?

据我所知,我无法组合sort和unique命令,因为sort没有显示重复项的选项.

谢谢,史蒂夫

小智 15

你可以保持简单:

sort -uf
#where sort -u = the unique findings
#      sort -f = insensitive case
Run Code Online (Sandbox Code Playgroud)


Jon*_*ler 5

我认为关键是预处理数据:

file="EN-IT_Corpus.txt"
dups="dupes.$$"
sed 's/        .*//' $file | sort -f | uniq -i -D > $dups
fgrep -i -f $dups $file
Run Code Online (Sandbox Code Playgroud)

sed命令只生成英文单词; 这些是按大小写不敏感的排序,然后通过uniq不区分大小写的方式运行,只打印重复的条目.然后再次处理数据文件,用fgrep或查找那些重复的键grep -F,指定要在文件中查找的模式-f $dups.显然(我希望)sed命令中的大空白是一个标签; 您可以\t根据您的shell等编写sed.

事实上,使用GNU grep,您可以:

sed 's/        .*//' $file |
sort -f |
uniq -i -D |
fgrep -i -f - $file
Run Code Online (Sandbox Code Playgroud)

如果重复的数量非常大,你可以用以下方式将它们压缩:

sed 's/        .*//' $file |
sort -f |
uniq -i -D |
sort -f -u |
fgrep -i -f - $file
Run Code Online (Sandbox Code Playgroud)

给定输入数据:

What a surprise?        Vous etes surpris?
What are you doing?        Che cosa stai facendo?
WHAT ARE YOU DOING?        Che diavolo stai facendo?
Provacation         Provacatore
what are you doing?        Qual è il tuo problema amico?
Ambiguous        Ambiguere
Run Code Online (Sandbox Code Playgroud)

所有这些的输出是:

What are you doing?        Che cosa stai facendo?
WHAT ARE YOU DOING?        Che diavolo stai facendo?
what are you doing?        Qual è il tuo problema amico?
Run Code Online (Sandbox Code Playgroud)


jim*_*ara 5

或这个:

独特的:

awk '!arr[tolower($1)]++'  inputfile > unique.txt
Run Code Online (Sandbox Code Playgroud)

重复

awk '{arr[tolower($1)]++; next} 
END{for (i in arr {if(arr[i]>1){print i, "count:", arr[i]}} }' inputfile > dup.txt
Run Code Online (Sandbox Code Playgroud)