Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

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…

Tuesday, July 8, 2008

Argument of the previous command

To use the last argument of the previous command line as an argument, use $_.

For example:
$ ls -l /home/sanju/somefile
$ vi $_

It will open /usr/home/somefile using vi editor.