Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm confusing use of uniq command, can anyone explain this command and how to use it?

How to use uniq without specifying any option?

Any example would be helped and appreciated

share|improve this question
6  
Have you tried reading the man page for uniq? man uniq. –  maxmackie Mar 8 '13 at 3:05

1 Answer 1

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

share|improve this answer
    
I have to downvote this because it doesn't appear to answer the question at all. The question is about uniq, not sort. Data does need to be sorted for uniq to work, but that is not included here. –  jordanm Mar 8 '13 at 6:19
    
@jordanm ah, I take it wrong, answer updated, thanks for pointing out –  warl0ck Mar 8 '13 at 6:26
    
However, all my uses of uniq combine with sort –  Bernhard Mar 8 '13 at 12:30
    
Downvote removed –  jordanm Mar 8 '13 at 15:37
    
For completeness, I'd suggest including a demonstration of how uniq and sort work together; I agree that uniq is most useful when combined with sort. –  davidcl Mar 8 '13 at 17:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.