[Home]
HomePage RecentChanges Frequently Asked Questions

oawk

oawk is "old awk", it is the default /usr/bin/awk on Solaris and should not be used. You can also find it in The Heirloom Toolchest

Here are some reason why it's called "old" taken from this post by Ed Morton, if you have more please reply to the above thread and/or edit this page.

no conditions without explicit comparisons:

$ echo "foo" | /usr/xpg4/bin/awk '1{print}' 
foo 
$ echo "foo" | /usr/bin/awk '1==1{print}' 
foo 
$ echo "foo" | /usr/bin/awk '1{print}' 
awk: syntax error near line 1 
awk: bailing out near line 1 
$ echo "foo" | /usr/bin/awk '1==1{print}' 
foo 
$ echo "foo" | /usr/xpg4/bin/awk '!x{print}' 
foo 
$ echo "foo" | /usr/bin/awk '!x{print}' 
awk: syntax error near line 1 
awk: bailing out near line 1 
foo 
$ echo "foo" | /usr/bin/awk 'x!=0{print}' 
foo 

no ternary expressions:

$ echo "foo" | /usr/xpg4/bin/awk '{print (0ドル=="foo") ? "yes" : "no"}' 
yes 
$ echo "foo" | /usr/bin/awk '{print (0ドル=="foo") ? "yes" : "no"}' 
awk: syntax error near line 1 
awk: illegal statement near line 1 

no ARGC:

$ echo "foo" | /usr/xpg4/bin/awk '{print "<"ARGC">"}' 
<1> 
$ echo "foo" | /usr/bin/awk '{print "<"ARGC">"}' 
<> 

no sub()/gsub():

$ echo "foo" | /usr/xpg4/bin/awk '{print "<" sub(/o/,"X") ">"}' 
<1> 
$ echo "foo" | /usr/bin/awk '{print "<" sub(/o/,"X") ">"}' 
awk: syntax error near line 1 
awk: illegal statement near line 1 

no -v:

$ echo "foo" | /usr/xpg4/bin/awk -v var="X" '{print "<" 0,ドルvar ">"}' 
<foo X> 
$ echo "foo" | /usr/bin/awk -v var="X" '{print "<" 0,ドルvar ">"}' 
awk: syntax error near line 1 
awk: bailing out near line 1 

inexplicable parameter parsing (here thinks "<bar>" is arg to sprintf()):

$ echo "foo" | /usr/xpg4/bin/awk '{print sprintf("%s =",0ドル), "<bar>"}' 
foo = <bar> 
$ echo "foo" | /usr/bin/awk '{print sprintf("%s =",0ドル), "<bar>"}' 
foo = 

no functions:

$ echo "foo" | /usr/xpg4/bin/awk 'function bar(){print} {bar()}' 
foo 
$ echo "foo" | /usr/bin/awk 'function bar(){print} {bar()}' 
awk: syntax error near line 1 
awk: bailing out near line 1 

no dynamic REs:

$ echo "foo" | /usr/xpg4/bin/awk 'BEGIN{re="o"} 0ドル ~ re {print}' 
foo 
$ echo "foo" | /usr/bin/awk 'BEGIN{re="o"} 0ドル ~ re {print}' 
awk: syntax error near line 1 
awk: bailing out near line 1 

Hangs if no input and no explicit exit:

$ time /usr/xpg4/bin/awk 'BEGIN{print "begin"}' 
begin 
real 0m0.06s 
user 0m0.01s 
sys 0m0.02s 
$ time /usr/bin/awk 'BEGIN{print "begin"}' 
begin 
^?$ 

Can't delete an array element:

$ /usr/xpg4/bin/awk 'BEGIN{ a[1]=a[2]; delete a[1]; for (i in a) print 
i; exit }' 
2 
$ /usr/bin/awk 'BEGIN{ a[1]=a[2]; delete a[1]; for (i in a) print i; 
exit }' 
2 
1 

Can't test for an element being "in" an array:

$ /usr/xpg4/bin/awk 'BEGIN{ a[1]=7; if (1 in a) print a[1]; exit }' 
7 
$ /usr/bin/awk 'BEGIN{ a[1]=7; if (1 in a) print a[1]; exit }' 
awk: syntax error near line 1 
awk: illegal statement near line 1 

No FNR variable:

$ cat file1 
a 
$ cat file2 
b 
$ /usr/xpg4/bin/awk 'NR==FNR{print}' file1 file2 
a 
$ /usr/bin/awk 'NR==FNR{print}' file1 file2 

No match() function:

$ /usr/xpg4/bin/awk '{print match(0,ドル"a")}' file1 file2 
1 
0 
$ /usr/bin/awk '{print match(0,ドル"a")}' file1 file2 
awk: syntax error near line 1 
awk: illegal statement near line 1 

FS cannot be an RE:

$ echo "faobo" | /usr/xpg4/bin/awk '{ print 1,ドル2,ドル3ドル }' FS="[ab]" 
f o o 
$ echo "faobo" | /usr/bin/awk '{ print 1,ドル2,ドル3ドル }' FS="[ab]" 
faobo

Cannot set 0ドル:

$ /usr/xpg4/bin/awk 'BEGIN{0ドル="foo"; print}' 
foo 
$ /usr/bin/awk 'BEGIN{0ドル="foo"; print}' 
awk: can't set 0ドル 

Strings can unexpectedly become numeric variables:

$ /usr/xpg4/bin/awk 'BEGIN{ c=3; print "c=" ++c; exit }' 
c=4 
$ /usr/bin/awk 'BEGIN{ c=3; print "c=" ++c; exit }' 
03 
$ /usr/xpg4/bin/awk 'BEGIN{ c=3; print "c=" ++c; print ++"c=" c; exit }' 
/usr/xpg4/bin/awk: syntax error Context is: 
>>> BEGIN{ c=3; print "c=" ++c; print ++"c=" <<< 
$ /usr/bin/awk 'BEGIN{ c=3; print "c=" ++c; print ++"c=" c; exit }' 
03 
23 

Edit this page View other revisions Administration
Last edited 2012年01月24日 08:29 UTC by pgas (diff)

Powered by sdf Creative Commons License <pierre.gaston+awk@gmail.com>

Awk Wiki by #awk is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

AltStyle によって変換されたページ (->オリジナル) /