version : check_your_awk version 0.2 (2011-12-10) time : 2011-12-10 21:13:49 uname : Linux a-laptop 2.6.32-36-generic #79-Ubuntu SMP Tue Nov 8 22:29:26 UTC 2011 i686 GNU/Linux nawk : GNU Awk 3.1.6 gawk : GNU Awk 3.1.6 mawk : mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan busybox : BusyBox v1.13.3 (Ubuntu 1:1.13.3-1ubuntu11) multi-call binary original-awk : awk version 20091126 ================================================== func ================================================== [code] awk 'func a(){ print "hello" } BEGIN{ a() }' 2>&1 [nawk] hello [gawk] hello [mawk] mawk: line 2: function a never defined mawk: line 2: function a never defined [busybox] hello [original-awk] hello ================================================== length() ================================================== [code] awk 'BEGIN{ a[0]=1; a[1]=2; print length(a) }' 2>&1 [nawk] 2 [gawk] 2 [mawk] mawk: line 1: illegal reference to array a [busybox] 0 [original-awk] 2 ================================================== close() ================================================== [code] awk 'BEGIN{ f="h9g7Tnw3"; while (getline s < f > 0) {print s;}; print "open done."; close(f); print "close done." }' 2>&1 [nawk] open done. close done. [gawk] open done. close done. [mawk] open done. close done. [busybox] open done. Segmentation fault [original-awk] open done. close done. ================================================== regex character class ================================================== [code] awk 'BEGIN{ s="a b"; if (s ~ /a[[:space:]]b/) {print s} else {print "unmatched"} }' 2>&1 [nawk] a b [gawk] a b [mawk] unmatched [busybox] a b [original-awk] a b ================================================== hyphen in regex (1) ================================================== [code] awk 'BEGIN{ s="a-b"; if (s ~ /a[a\-a]b/) {print s} else {print "unmatched"} }' 2>&1 [nawk] a-b [gawk] a-b [mawk] a-b [busybox] awk: bad regex 'a[a\-a]b': Invalid range end [original-awk] a-b ================================================== hyphen in regex (2) ================================================== [code] awk 'BEGIN{ s="a-b"; if (s ~ /a[\#\-\#]b/) {print s} else {print "unmatched"} }' 2>&1 [nawk] a-b [gawk] a-b [mawk] a-b [busybox] unmatched [original-awk] a-b ================================================== backslash in regex ================================================== [code] awk 'BEGIN{ s="a(b)c"; if (s ~ "a\(b\)c") {print s} else {print "unmatched"} }' 2>&1 [nawk] nawk: warning: escape sequence `\(' treated as plain `(' nawk: warning: escape sequence `\)' treated as plain `)' unmatched [gawk] gawk: warning: escape sequence `\(' treated as plain `(' gawk: warning: escape sequence `\)' treated as plain `)' unmatched [mawk] a(b)c [busybox] unmatched [original-awk] unmatched ================================================== backslash in sub() and gsub() ================================================== [code] awk 'BEGIN{ s="a"; sub(/a/, "\\\\", s); print s }' 2>&1 [nawk] \\ [gawk] \\ [mawk] \ [busybox] \\ [original-awk] \\ ================================================== gsub() ================================================== [code] awk 'BEGIN{ s1=s2="aaabbbaaa"; gsub(/^a/, "", s1); gsub(/^a*/, "", s2); printf "s1 : %-10s s2 : %s\n", s1, s2 }' 2>&1 [nawk] s1 : aabbbaaa s2 : bbbaaa [gawk] s1 : aabbbaaa s2 : bbbaaa [mawk] s1 : bbbaaa s2 : bbb [busybox] s1 : aabbbaaa s2 : bbbaaa [original-awk] s1 : aabbbaaa s2 : bbbaaa ================================================== output null byte (1) ================================================== [code] awk 'BEGIN{ print "\0" }' 2>&1 | od -t x1 | head -1 [nawk] 0000000 00 0a [gawk] 0000000 00 0a [mawk] 0000000 0a [busybox] 0000000 0a [original-awk] 0000000 0a ================================================== output null byte (2) ================================================== [code] awk 'BEGIN{ printf "%c", "\0" }' 2>&1 | od -t x1 | head -1 [nawk] 0000000 00 [gawk] 0000000 00 [mawk] 0000000 00 [busybox] 0000000 [original-awk] 0000000 ================================================== output null byte (3) ================================================== [code] awk 'BEGIN{ printf "%c", 0 }' 2>&1 | od -t x1 | head -1 [nawk] 0000000 00 [gawk] 0000000 00 [mawk] 0000000 00 [busybox] 0000000 [original-awk] 0000000 00 ================================================== handling null byte (1) ================================================== [code] awk 'BEGIN{ s=sprintf("%c", 0); printf "%c", s }' 2>&1 | od -t x1 | head -1 [nawk] 0000000 00 [gawk] 0000000 00 [mawk] 0000000 00 [busybox] 0000000 [original-awk] 0000000 ================================================== handling null byte (2) ================================================== [code] awk 'BEGIN{ s=sprintf("%c", 0); print length(s) }' 2>&1 [nawk] 1 [gawk] 1 [mawk] 0 [busybox] 0 [original-awk] 0 ================================================== handling null byte (3) ================================================== [code] awk 'BEGIN{ s=sprintf("aa%cbb", 0); printf "%s", s }' 2>&1 | od -t x1 | head -1 [nawk] 0000000 61 61 00 62 62 [gawk] 0000000 61 61 00 62 62 [mawk] 0000000 61 61 62 62 [busybox] 0000000 61 61 [original-awk] 0000000 61 61 ================================================== handling null byte (4) ================================================== [code] awk 'BEGIN{ s=sprintf("aa%cbb", 0); print length(s) }' 2>&1 [nawk] 5 [gawk] 5 [mawk] 4 [busybox] 2 [original-awk] 2 ================================================== handling null byte (5) ================================================== [code] dd if=/dev/zero bs=1 count=5 2> /dev/null | awk 'BEGIN{ RS=";" } END{ print NR }' 2>&1 [nawk] 1 [gawk] 1 [mawk] 1 [busybox] 5 [original-awk] 1 ================================================== handling null byte (6) ================================================== [code] dd if=/dev/zero bs=1 count=5 2> /dev/null | awk 'BEGIN{ RS=sprintf("%c", 0) } END{ print NR }' 2>&1 [nawk] 5 [gawk] 5 [mawk] 0 [busybox] 1 [original-awk] 1 ================================================== number or string (1) ================================================== [code] echo "a10" | awk 'function f(s){ sub(/a/, "", s); print ((s > 5) ? "num" : "str") } { f("a10"); f($1); }' 2>&1 [nawk] str num [gawk] str num [mawk] str str [busybox] str str [original-awk] str str ================================================== number or string (2) ================================================== [code] echo "10" | awk 'function f(s){ print ((s > 5) ? "num" : "str") } { s1=s2=10; s3=s4=$1; sub(/a/, "", s2); sub(/a/, "", s4); f(s1); f(s2); f(s3); f(s4) }' 2>&1 [nawk] num num num num [gawk] num num num num [mawk] num num num num [busybox] num str num str [original-awk] num num num num