The uniq command is used to remove adjacent duplicate lines from a file. It will only remove lines that are duplicates of the immediately preceding line. If there are duplicates that are not adjacent to each other, they will not be removed.
The basic syntax for the uniq command is as follows:
uniq [OPTIONS] [IN_FILE] [OUT_FILE] .
Here are some common options for the uniq command:
$ echo -e ' aaa\n aaa\n bbb\n aaa\n' | uniq ← 用〝uniq〞 刪除相鄰且重複的行 aaa bbb aaa ←this line is not deleted |
n the above test, the line "aaa" appeared three times, but it was only removed when it was adjacent to the previous line. The non-adjacent duplicate line was not removed.
For more uniq options and examples, you can refer to the provided link.