The following options are available:
|Precede each output line with the count of the number of times the line occurred in the input, followed by a single space.
|Output a single copy of each line that is repeated in the input.
Output all lines that are repeated (like
|Do not separate groups of lines (this is the default).
|Output an empty line before each group of lines.
|Output an empty line after each group of lines.
|Ignore the first num fields in each input line when doing comparisons. A field is a string of non-blank characters separated from adjacent fields by blanks. Field numbers are one based, i.e., the first field is field one.
|Case insensitive comparison of lines.
Ignore the first
characters in each input line when doing comparisons.
If specified in conjunction with the
|Only output lines that are not repeated in the input.
Madrid Lisbon Madrid
The following command reports three different lines since identical elements are not adjacent:
$ uniq -u cities.txt Madrid Lisbon Madrid
Sort the file and count the number of identical lines:
$ sort cities.txt | uniq -c 1 Lisbon 2 Madrid
Assuming the following content for the file cities.txt:
madrid Madrid Lisbon
Show repeated lines ignoring case sensitiveness:
$ uniq -d -i cities.txt madrid
Same as above but showing the whole group of repeated lines:
$ uniq -D -i cities.txt madrid Madrid
Report the number of identical lines ignoring the first character of every line:
$ uniq -s 1 -c cities.txt 2 madrid 1 Lisbon
|June 7, 2020
|The most horrifying thing about Unix is that, no matter how many times you hit yourself over the head with it, you never quite manage to lose consciousness. It just goes on and on.
|— Patrick Sobalvarro