Categories
technology

favourite UNIX commands, uniq

One of my favourites is the uniq command. The command enables you to report or omit repeated lines in a file.Here’s some switch details from the man page.

-c, --count
prefix lines by the number of occurrences
-d, --repeated
only print duplicate lines
-u, --unique
only print unique lines

So if you wanted to find and sort common lines in two files you could do something like.
# cat file1 file2 ! uniq -d | sort
Quite a few friends have been asked to do something similar in interviews. I always find that a bit funny as it takes a minute to look this stuff up online so it’s probably not crucial to know every Unix command off the top of your head. Although there’s probably some nerdy bragging rights but with a 96% nerd test score I think I’ll pass.

Leave a Reply

Your email address will not be published. Required fields are marked *