awk

Ok, how is awk an underdog in scientific computing. Well, it is very well suited for performing simple tasks on data files.

E.g., you may run

awk ‘{print $1-45,$2/1800*0.82}’ intr.dat

To shift the x value from the first column of the data file, and scale the y value from the second. Or anything one could imagine. The result can be put in another file ( ” … > result.dat “), or piped into another program, e.g. xmgrace:

awk ‘{print $1-45,$2/1800*0.82}’ intr.dat > xmgrace -pipe

Script files are also helpful to perform more complex operations on data files, like the following example, that prints just certain lines of a file:

BEGIN{
nn=1000
}

(NR==1) { nn=$1+2 }

{ if ((NR-1)%nn==0) { print $1 }
else if ((NR-1)%nn!=nn-1) {
print $1, 1*$4
}
}

END{
print nn
}

Update

awk + gnuplot together!!!

Look at this beautiful command that plots a data file, plus the data in line 2:

plot ‘data.dat’ w l, “< awk ‘(NR==2) {print $0}’ data.dat “

The command must be executed from gnuplot. It works by “piping” the output of the awk command directly into gnuplot.