1、測試數據
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt ## 測試數據 a g b d a b b d c b
2、統計重復項
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort a.txt | uniq -d ## 重復項 a b d root@ubuntu01:/home/test# sort a.txt | uniq -D ## 重復項 a a b b b b d d
3、去重復
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort -u a.txt ## 去重復 a b c d g root@ubuntu01:/home/test# sort a.txt | uniq ## 去重復 a b c d g
4、取唯一項
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort a.txt | uniq -u ## 取唯一項 c g
5、統計重復次數
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort a.txt | uniq -c ## 統計重復次數 2 a 4 b 1 c 2 d 1 g root@ubuntu01:/home/test# sort a.txt | uniq -c | sed 's/^[\t ]*//g' ## 統計重復次數 2 a 4 b 1 c 2 d 1 g