Skip to content

Commit

Permalink
sort uniq first (#954)
Browse files Browse the repository at this point in the history
'uniq' does not detect repeated lines unless they are adjacent, so we need to sort them
  • Loading branch information
alfredbez authored and leostera committed Jul 15, 2016
1 parent 30c40fe commit 8336898
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pages/common/uniq.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# 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.
- Display each line once:

`uniq {{file}}`
`sort {{file}} | uniq`

- Display only unique lines:

`uniq -u {{file}}`
`sort {{file}} | uniq -u`

- Display only duplicate lines:

`uniq -d {{file}}`
`sort {{file}} | uniq -d`

- Display number of occurences of each line along with that line:

`uniq -c {{file}}`
`sort {{file}} | uniq -c`

- Display number of occurences of each line, sorted by the most frequent:

`uniq -c {{file}} | sort -nr`
`sort {{file}} | uniq -c | sort -nr`

0 comments on commit 8336898

Please sign in to comment.