How do I extract certain columns from a text file in Unix?
Somehow I can never remember the cut command in Unix. But I occasionally want to remove certainly columns from a text file of data. cut will do that, and can even handle different column delimiters.
Here is a simple example.
Data File (tab-delimited)
111 222 3333 444 555 666
111 222 3333 444 555 666
111 222 3333 444 555 666
111 222 3333 444 555 666
111 222 3333 444 555 666
Command
cut -f1,4,6 filename
Output
111 444 666
111 444 666
111 444 666
111 444 666
111 444 666
There are two other examples in the Search and Replace section of this KB article.
http://kb.ucla.edu/articles/unix-cheat-sheets-and-tricks
More options are available in the Unix man pages for cut. Type man cut