Bash 文本文件中一行的非重复项
如何使用bash在文本文件的行中仅显示不重复的单词。例如,我在文本文件中有以下行:Bash 文本文件中一行的非重复项,bash,unix,duplicates,Bash,Unix,Duplicates,如何使用bash在文本文件的行中仅显示不重复的单词。例如,我在文本文件中有以下行: 1001 1002 1003 1002 1003 我只想显示1001。我不想显示行中任何重复的字 我正在努力 #!/bin/bash file="/tmp/t1" while IFS= read line do echo $line | xargs -n1 | sort -u |xargs done < "$file" 您可以为此使用seawk: s='1001 1002 1003 1002
1001 1002 1003 1002 1003
我只想显示1001。我不想显示行中任何重复的字
我正在努力
#!/bin/bash
file="/tmp/t1"
while IFS= read line
do
echo $line | xargs -n1 | sort -u |xargs
done < "$file"
您可以为此使用se
awk
:
s='1001 1002 1003 1002 1003'
awk '{delete freq; for (i=1; i<=NF; i++) freq[$i]++;
for (i in freq) if (freq[i] == 1) print i}' <<< "$s"
解决方案的修复程序
$ while IFS= read line;
do echo $line |
xargs -n1 |
sort |
uniq -u |
xargs;
done < file
$while IFS=读取行;
做回显$line |
xargs-n1|
排序|
uniq-u|
xargs;
完成<文件
NB.uniq-u
和sort-u
做不同的事情。本质上sort | uniq
相当于sort-u
。但是uniq-u
只返回非重复条目(补码是uniq-d
)
1001
$ while IFS= read line;
do echo $line |
xargs -n1 |
sort |
uniq -u |
xargs;
done < file