【Linux】重複行と件数を出力する
コマンド
$ cat test.txt | sort | uniq -c | grep -v '1 '
処理の流れ
- cat test.txt | sort でファイル内容をソートする
- uniq -c で重複を除外し件数を出力する
- grep -v ‘1 ’ で1件の行を除外する
具体例
$ cat test.txt AAA BBB CCC BBB AAA DDD AAA BBB $ cat test.txt | sort AAA AAA AAA BBB BBB CCC DDD $ cat test.txt | sort | uniq -c 3 AAA 2 BBB 1 CCC 1 DDD $ cat test.txt | sort | uniq -c | grep -v '1 ' 3 AAA 2 BBB
2017/08/30追記
処理対象のデータリストは空白を含まないデータの前提です。
空白を含むデータに対して実施したい場合は、
”grep -v ‘1 '”を調整する必要があります。