Uniq command
Function: Outputs or ignores duplicate rows in a file
Format: uniq [option] [File|stdin]
[Email protected]:~/linux/Uniq$CatGhostwu.txt192.168.1.2192.168.1.8192.168.1.3192.168.1.3192.168.1.9192.168.1.8192.168.1.8192.168.1.0192.168.1.3[email protected]:~/linux/Uniq$UniqGhostwu.txt192.168.1.2192.168.1.8192.168.1.3192.168.1.9192.168.1.8192.168.1.0192.168.1.3
A continuous repeating row is removed. If you want to keep only the unique file, you can use the option-u
[Email protected]:~/linux/uniquniq -192.168. 1.2 192.168. 1.8 192.168. 1.9 192.168. 1.0 192.168. 1.3
-C: To repeat and calculate the number of occurrences per row
[Email protected]:~/linux/Uniq$Uniq-C Ghostwu.txt1 192.168.1.2 1 192.168.1.8 2 192.168.1.3 1 192.168.1.9 2 192.168.1.8 1 192.168.1.0 1 192.168.1.3[email protected]:~/linux/Uniq$Cat-N ghostwu.txt1 192.168.1.2 2 192.168.1.8 3 192.168.1.3 4 192.168.1.3 5 192.168.1.9 6 192.168.1.8 7 192.168.1.8 8 192.168.1.0 9 192.168.1.3
Can be sorted with sort command, then repeat, the result is also unique
[Email protected]:~/linux/uniqsortuniq -C 1192.168. 1.0 1192.168. 1.2 3192.168. 1.3 3192.168. 1.8 1192.168. 1.9
-D: Show only duplicate rows
[Email protected]:~/linux/uniquniq -192.168. 1.3 192.168. 1.8
Linux Common basic commands: uniq-to repeat