-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'uniq' does not detect repeated lines unless they are adjacent, so we need to sort them
- Loading branch information
Showing
1 changed file
with
6 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |