2016-01-12 10:08:52 -05:00
|
|
|
# uniq
|
|
|
|
|
2024-02-14 17:25:13 -03:00
|
|
|
> Output the unique lines from a input or file.
|
2016-07-15 13:18:37 +02:00
|
|
|
> Since it does not detect repeated lines unless they are adjacent, we need to sort them first.
|
2025-01-18 18:45:33 +05:30
|
|
|
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/uniq-invocation.html>.
|
2016-01-12 10:08:52 -05:00
|
|
|
|
|
|
|
- Display each line once:
|
|
|
|
|
2022-12-04 10:12:49 +01:00
|
|
|
`sort {{path/to/file}} | uniq`
|
2016-01-12 10:08:52 -05:00
|
|
|
|
|
|
|
- Display only unique lines:
|
|
|
|
|
2022-12-04 10:12:49 +01:00
|
|
|
`sort {{path/to/file}} | uniq -u`
|
2016-01-12 10:08:52 -05:00
|
|
|
|
|
|
|
- Display only duplicate lines:
|
|
|
|
|
2022-12-04 10:12:49 +01:00
|
|
|
`sort {{path/to/file}} | uniq -d`
|
2016-01-12 10:08:52 -05:00
|
|
|
|
2017-05-12 11:29:18 +02:00
|
|
|
- Display number of occurrences of each line along with that line:
|
2016-01-12 10:08:52 -05:00
|
|
|
|
2022-12-04 10:12:49 +01:00
|
|
|
`sort {{path/to/file}} | uniq -c`
|
2016-07-10 10:26:13 +01:00
|
|
|
|
2017-05-12 11:29:18 +02:00
|
|
|
- Display number of occurrences of each line, sorted by the most frequent:
|
2016-07-10 10:26:13 +01:00
|
|
|
|
2022-12-04 10:12:49 +01:00
|
|
|
`sort {{path/to/file}} | uniq -c | sort -nr`
|