Uniq
The uniq command can remove duplicate rows from sorted files. Therefore, uniq is often used with sort. That is to say, to make uniq work, all repeated rows must be adjacent.
Uniq syntax
[Root @ WWW ~] # Uniq [-ICU] Option and parameter:-I: Ignore case-insensitive characters;-C: Count-u: show only unique rows
The content of testfile is as follows:
Cat testfilehelloworldfriendhelloworldhello
Directly Delete unordered files. No rows are deleted.
# Uniq testfile helloworldfriendhelloworldhello
Sort files. deduplication is used by default.
# Cat words | sort | uniqfriendhelloworld
Duplicate rows are deleted after sorting, and the number of repeated rows is output at the beginning of the row.
# Sort testfile | uniq-C1 friend3 hello2 world
Only duplicate rows are displayed, and the number of repeated rows is displayed at the beginning of the row.
# Sort testfile | uniq-DC3 hello2 world
Only show non-repeated rows
Sort testfile | uniq-ufriend