tldr/pages/common/uniq.md

26 lines
636 B
Markdown
Raw Normal View History

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