awk - animeshtrivedi/notes GitHub Wiki

removing scientific annotation in awk printing

By default awk uses -e format and wraps large ints into e+06. But this can be changed by setting formatting sting with printf[1].

awk '{printf "%f \t\t %f", $2, $3/1024}'

[1] https://www.gnu.org/software/gawk/manual/html_node/Printf.html

printing large numbers with awk

awk's printf routine has %i for integers but it won't print anything longer than INTEGER.MAX_VALUE. So here is the trick. Use print but set its format.

awk 'BEGIN {OFMT = "%.0f"} {i=i+$1;j=j+($3*$1);} END {print i; print j}' md5sums 

reference: https://fordodone.com/2013/05/27/printing-large-integers-with-awk/