version : check_your_awk version 0.1 (2011-12-04) time : 2011-12-04 15:49:29 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() }' [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) }' [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." }' [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"} }' [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"} }' [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"} }' [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"} }' [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="\\"; sub(/\\/, "\\\\", s); print s }' [nawk] \\ [gawk] \\ [mawk] \ [busybox] \\ [original-awk] \\ ============================================ gsub() ============================================ [code] awk 'BEGIN{ s="aaabbbccc"; gsub(/^[^b]*/, "", s); print s }' [nawk] bbbccc [gawk] bbbccc [mawk] bbb [busybox] bbbccc [original-awk] bbbccc ============================================ output null byte 1 ============================================ [code] awk 'BEGIN{ print "\0" }' | 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" }' | 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 }' | od -t x1 | head -1 [nawk] 0000000 00 [gawk] 0000000 00 [mawk] 0000000 00 [busybox] 0000000 [original-awk] 0000000 00 ============================================ number or string ============================================ [code] printf "%s" "a" | awk '{ s=$1; sub(/a/, "10", s); r = (s > 5) ? "true" : "false"; print r } ' [nawk] true [gawk] true [mawk] false [busybox] false [original-awk] false