- published: 24 Apr 2015
- views: 3541595
uniq is a Unix utility which, when fed a text file, outputs the file with adjacent identical lines collapsed to one. It is a kind of filter program. Typically it is used after sort. It can also output only the duplicate lines (with the -d option), or add the number of occurrences of each line (with the -c option).
An example: To see the list of lines in a file, sorted by the number of times each occurs:
Using uniq like this is common when building pipelines in shell scripts.
You tell me that you need to spend sometime alone
You tell me that you think it's best if I'd go home now
I get my coat from off the floor, I'm out the door
Walking home alone, my love has left
My head, my heart all torn apart
My mind's exploding
Crying my eyes out over you
It must be hard for you to believe that I might love you
Just try to understand I just want you to want me too
You made me fall in love again, you angel
How you take my breath away, I live for you
It must be hard for you to believe that I might love you anyway
Just try to understand I just wanted you to want me too