I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Saturday 19 September 2009

What the Cut?

Well I just learnt about a cool command: cut. Under UNIX, cut allows you to cut some portion of lines of a file. This is really cool.

Some examples:

for a file (with fields separated with \t):

$-> cat file
line 1 FIELD 2 FIELD 3 FIELD 4 FIELD 5 FIELD 6 FIELD 7
line 2 FIELD 2 FIELD 3 FIELD 4 FIELD 5 FIELD 6 FIELD 7
line 3 FIELD 2 FIELD 3 FIELD 4 FIELD 5 FIELD 6 FIELD 7
line 4 FIELD 2 FIELD 3 FIELD 4 FIELD 5 FIELD 6 FIELD 7
line 5 FIELD 2 FIELD 3 FIELD 4 FIELD 5 FIELD 6 FIELD 7

$-> cat file|cut -c '2-4'
FIELD 2 FIELD 3 FIELD 4
FIELD 2 FIELD 3 FIELD 4
FIELD 2 FIELD 3 FIELD 4
FIELD 2 FIELD 3 FIELD 4
FIELD 2 FIELD 3 FIELD 4
and you can stick a file back together using paste. Isn't the unix philosophy cool? Or am I a geek?