Monday, March 30, 2009

AUC #1: paste

auc2AUC 1 - Arbitrary Unix Command #1
I thought it might be useful to cover some obscure unix commands that you may find useful in your day to day system administration. My primary work machine is a Macbook Pro these days, so I'll lean towards cover commands that come with OS X. Most unix operating systems (OpenBSD, FreeBSD, Linux, Solaris) will likely have the commands I cover as well so only the Microsoft-only folks will be left out. (sorry)

Up first is the command that took my 15 minutes to remember at work today when I wanted to take a list with one column and seperate it into a list with two columns. Here, a visual will make this easier to explain:

List of foo

This is a list of a person and their favorite fruit. You want to convert this into a table like this:

Useful lookup table

But your table is 100,000 lines long and you don't want to do it by hand, or mess with any complex regular expressions in sed, awk or a scripting language.

The unix command paste does exactly this. Here's how simple the syntax is:
cat 100k_file | paste - - > lookup_table

Now that's pretty simple. Just change the number of "-"'s to how many columns you want.

paste can do some other things but this is how I found it to be useful. If you have another tip on paste, the comment box below awaits.

No comments:

Post a Comment