From 8336898ea9d97891bd81a0a3a0b7f71835814baf Mon Sep 17 00:00:00 2001 From: Alfred Bez Date: Fri, 15 Jul 2016 13:18:37 +0200 Subject: [PATCH] sort uniq first (#954) 'uniq' does not detect repeated lines unless they are adjacent, so we need to sort them --- pages/common/uniq.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pages/common/uniq.md b/pages/common/uniq.md index 1ed819169..a51eff2f9 100644 --- a/pages/common/uniq.md +++ b/pages/common/uniq.md @@ -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`