Monday, July 28, 2008

Cut and paste text files by columns

How many times have you wanted to edit those results files columnwise?

Here’s a generic UNIX way: (startcol and endcol refer to character columns, including whitespace. Tab counts as 1.)

cut -cstartcol-endcol file {>receiving file} paste sourcefile1 sourcefile2 {>final file}

I like to preview and fine-tune my commands by looking at the result on standard out (the shell window) and then redirecting output to a (temporary) file when things look right. Those feeling really adventurous can combine things into a single command line…

No comments: