I'm confused on the use of the uniq
command. Can anyone explain this command and how to use it?
How can I use uniq
without specifying any option? Any example would be helped and appreciated.
I'm confused on the use of the uniq
command. Can anyone explain this command and how to use it?
How can I use uniq
without specifying any option? Any example would be helped and appreciated.
uniq read file line-by-line, and only consider a duplicate when the current line is exactly the same as the last line,
i.e for a input file like this,
1
1
2
1
You'll get an output like this,
1
2
1
To use it, you can either run it though a pipe, i.e
command | uniq
Or get the input from a file like this,
uniq < input > output
uniq
, not sort
. Data does need to be sorted for uniq
to work, but that is not included here.
– jordanm
Mar 08 '13 at 06:19
uniq
and sort
work together; I agree that uniq
is most useful when combined with sort
.
– davidcl
Mar 08 '13 at 17:06
man uniq
. – nopcorn Mar 08 '13 at 03:05