« Lisbon, many steps too far & in the wrong direction? | Main | Mary Hanafin creates another roadblock to the WIT university campaign »

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.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on May 3, 2008 12:27 PM.

The previous post in this blog was Lisbon, many steps too far & in the wrong direction?.

The next post in this blog is Mary Hanafin creates another roadblock to the WIT university campaign.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33