Sometimes it's all about the aesthetics.


abs() in awk command

It has been very annoying that there is no intrinsic absolute function in awk, but it's still easy to do it by ourself:

$ paste tmp1/energy.txt tmp2/energy.txt tmp3/energy.txt tmp4/energy.txt \
? | awk 'function abs(x){return (((x < 0.0) ? -x : x) + 0.0)}\
? {printf "%s %25.12f %25.12f %25.12f %25.12f\n", $1,\
? abs($2-$2),abs($4-$2),abs($6-$2),abs($8-$2)}'

1 comment:

Akhil said...

Nice Article.
Some examples on Find Command and Awk Command