Loose-Info.com
Last Update 2014/03/11
TOP - Unix系OS - FreeBSD - uniq(1)

ファイル内の重複行を処理します。

uniq オプション1 ファイルパス1 ファイルパス2 オプション1(任意) -c 行の出現回数および行の内容の出力 -d 重複した行のみ出力 -f 値1 (値1)個の列の内容を無視 -i 大文字小文字を区別しない -s 値1 行頭から(値1)個の文字を無視 -u 重複しなかった行のみ出力 ファイルパス1 読み込むファイル ファイルパス2 出力するファイル 指定の無い場合は標準出力

※ オプションなどは個人的に重要と考えられるものを記述しており、記載の無いものは、manページや関連書籍などを参照願います。
※ 実行例の記述は、不要と考えられる部分の削除などの修正を行ったものを掲載しています。
※ 実行例の実行環境はFreeBSD 9.1です。

(例) オプション無し
実行結果
$ cat test.txt 123456 aaaaaa 123456 abcdefg ee cc ee $ sort -o test2.txt test.txt $ cat test2.txt 123456 123456 aaaaaa abcdefg cc ee ee $ uniq test2.txt 123456 aaaaaa abcdefg cc ee

(例) オプション -c
実行結果
$ cat test2.txt 123456 123456 aaaaaa abcdefg cc ee ee $ uniq -c test2.txt 2 123456 1 aaaaaa 1 abcdefg 1 cc 2 ee

(例) オプション -d
実行結果
$ cat test2.txt 123456 123456 aaaaaa abcdefg cc ee ee $ uniq -d test2.txt 123456 ee

(例) オプション -i
実行結果
$ cat test2.txt 123456 123456 aaaaaa abcdefg cc Ee ee $ uniq -i test2.txt 123456 aaaaaa abcdefg cc Ee

(例) オプション -f
実行結果
$ cat test.txt 001 abcde 002 abcde 003 ggggg 004 aaa 005 aaa $ uniq -f 1 test.txt 001 abcde 003 ggggg 004 aaa

(例) オプション -s
実行結果
$ cat test.txt 001 abcde 002 abcde 003 ggggg 004 aaa 005 aaa $ uniq -s 3 test.txt 001 abcde 003 ggggg 004 aaa

(例) オプション -u
実行結果
$ cat test2.txt 123456 123456 aaaaaa abcdefg cc ee ee $ uniq -u test2.txt aaaaaa abcdefg cc