Tuesday, March 8, 2011

I love awk, grep, and sort

Not to say the obvious (which is I like linux a lot!), awk really comes handy so often...
I have some files of my research (I'm a senior at college), which have like 9 columns of rather big numbers, representing some benchmark results.

Having to put them in an openoffice spreadsheet after sorting them, my friends grep, awk , and sort really helped me out:

blosum 0.824/0.735 0.894/0.432 0.694/0.349 0.728/0.364 0.832/0.595 0.817/0.610 0.794/0.495
gonnet 0.865/0.781 0.934/0.596 0.756/0.447 0.822/0.543 0.876/0.661 0.864/0.692 0.851/0.606
pam 0.764/0.639 0.851/0.321 0.582/0.175 0.672/0.161 0.666/0.388 0.746/0.485 0.707/0.337
jtt_aa_codon 0.840/0.747 0.927/0.562 0.769/0.494 0.798/0.439 0.809/0.555 0.842/0.653 0.829/0.559

I have a file with data like this (a lot more though...), and I want to sort those three fields by the 7th column's left value, and also separate the values divided by "/" and obviously print the first field...

$grep -E "pam|blosum|gonnet" whole_hyou.txt |awk '{print $1, $7}'|awk '{split($2, second, "/"); print $1, second[1], second[2]}'|sort -k 2 -r

gonnet 0.864 0.692
blosum 0.817 0.610
pam 0.746 0.485

Ah, and then I just select and press the mid button in openoffice, click on "space" as a separator, and I get right done what I wanted to do in almost no time...
I've seen my friends trying to do the same thing in windows...
I would kill myself/or die of boring if I had to waste my time like that!

No comments:

Post a Comment