University of California at Berkeley Department of Electrical Engineering & Computer Sciences Instructional & Electronics Support Group /share/b/pub/awk.help June 2, 2002 'awk' is a standard UNIX command that can process lines of a text file. It can identify individual fields, do arithmetic, do conditional ("if") statements and pattern matching, and print out the results. Each UNIX operating system has a version, typically located in /bin/awk. The UNIX systems in EECS also have a shared version that is the GNU version, called 'gawk'. It can be accessed as either /usr/sww/bin/awk /usr/sww/bin/gawk Type "man awk" for the local UNIX manual page. Type "man -M /usr/sww/pkg/gawk*/man gawk" for the SWW UNIX manual page. Type "awk --version" or "gawk --version" to see the version number. Gawk 3.0.3 Arithmetic Bug ------------------------- We received this bug report about Gawk 3.0.3: > From das@HAL9000.wox.org Sun May 26 03:30:19 2002 > From: David Schultz > It appears that in GNU AWK 3.0.3, the last operand in a sequence of > arithmetic expressions is incorrectly rounded to 0 if its absolute > value is less than 1. GNU AWK 3.0.6 has several annoying bugs, too, > but if you tell it to be compatable with bwk's AWK, they all go away. ;-) > Specifically, when you add 0.5 to a floating point number, the number > is sometimes unchanged. GNU AWK 3.0.6 and The One True AWK behave > differently. The workaround seems to be to say +1-0.5. > das@HAL9000:~> awk -V > awk version 20020210 > das@HAL9000:~> awk 'BEGIN { i = 0.5 + 0.5; printf("%f\n", i); }' > 1.000000 > > das@HAL9000:~> gawk --version > GNU Awk 3.0.6 > [snip GPL advertisement] > das@HAL9000:~> gawk 'BEGIN { i = 0.5 + 0.5; printf("%f\n", i); }' > 1.000000 > > pentagon ~/grading/sp02 > awk --version > GNU Awk 3.0.3 > [snip GPL advertisement] > pentagon ~/grading/sp02 > awk 'BEGIN { i = 0.5 + 0.5; printf("%f\n", i); }' > 0.000000 EECS Instructional Support 384/386 Cory, 333 Soda inst@eecs.berkeley.edu