tldr/pages/common/uniq.md

25 lines
535 B
Markdown
Raw Normal View History

2016-01-12 15:08:52 +00:00
# uniq
> Output the unique lines from the given input or file.
> Since it does not detect repeated lines unless they are adjacent, we need to sort them first.
2016-01-12 15:08:52 +00:00
- Display each line once:
`sort {{file}} | uniq`
2016-01-12 15:08:52 +00:00
- Display only unique lines:
`sort {{file}} | uniq -u`
2016-01-12 15:08:52 +00:00
- Display only duplicate lines:
`sort {{file}} | uniq -d`
2016-01-12 15:08:52 +00:00
- Display number of occurences of each line along with that line:
`sort {{file}} | uniq -c`
- Display number of occurences of each line, sorted by the most frequent:
`sort {{file}} | uniq -c | sort -nr`