HomePage RecentChanges Frequently Asked Questions Japanese Espańol

AwkFeatureComparison

This page lists which awk implementations support which features. Additions and corrections are very welcome.

FeaturePOSIX awkGNU awk 3.1.6Busybox awk 1.11.3mawk 1.3.3nawk (solaris 2.8)/usr/xpg4/bin/awk (solaris 2.8)tawk x.xxFreeBSD? awk 20070501(apparently this is the "one true awk")NetBSD? awk 20030729jawk 1.02
{m,n} repetition in REyesyes,with --re-interval or --posixyesnonoyesunknownyesnoyes
Special characters in RE (\w etc.)noyes (but not in POSIX mode)yesnononounknownnonono
using empty FS to split charactersno (undefined)yes, but not in POSIX modeyesyesnonounknownnonoyes
FS can match the empty stringunknown?noyesnononounknownnonoyes
split() splits chars with empty sepundefinedyes (both with // and "")yes (extra field with //)yes with "", no with //nonounknownyes with "", no with //yes (extra field with //)yes
sub()/gsub() can replace the empty regexunknown?yesyesyesonly with o* (see sample code)yesunknownyesyes, but only with an implicit regex (see sample code)yes
using a regex for RSno (undefined)yes, even in POSIX mode!yesyesnonounknownnonono
RTnoyes, but not in POSIX modeyesnononounknownnonono
-v to pass valuesyesyesyesyesyesyesunknownyesyesyes
ENVIRON arrayyesyesyesyesyesyesunknownyesyesyes
gensub()noyes, but not in POSIX modeyesnononounknownnoyes (no backrefs)no
strftime()noyes, but not in POSIX modeyesnononounknownnoyesno
length(array)noyes (new in 3.1.5), but not in POSIX modenonononounknownyes!yesno
asort()noyes, but not in POSIX modenonononounknownnonono
FNRyesyesyesyesyesyesunknownyesyesno
ARGV arrayyesyesyesyesyesyesunknownyesyesyes
print (and possibly others?) in for definitionyes?yesnonoyesnounknownyesyesyes
$0 contains the last record in the END blockyes?yesyesyesnonounknownyesnono

Finding out which features your awk supports

FeatureTest code # expected result if feature is supported
{m,n} repetition in REecho aaa|awk '/a{3}/' # aaa
Special characters in RE (\w etc.)echo 'a,b'|awk '/\<\w\W\w\>/' # a,b
using empty FS to split charactersecho abc|awk -F '' '{print NF}' # 3
FS can match the empty stringecho aaba|awk -F 'b*' '{print NF}' # >2
split() splits chars with empty sepecho abc|awk '{print split($0,a,"")}' # >1; also try with //
sub()/gsub() can replace the empty regex (explicit)echo abc|awk '{sub(//,"X")}1' # Xabc; also try with ""
sub()/gsub() can replace the empty regex (implicit)echo abc|awk '{sub(/o*/,"X")}1' # Xabc; also try with "o*"
using a regex for RSecho a4b|awk -v RS='[0-9]' 'NR==1' # a
RTecho a4b|awk -v RS='[0-9]' 'NR==1{print RT}' # 4
-v to pass valuesawk -v foo=bar 'BEGIN {print foo}' # bar
ENVIRON arraya=FOO awk 'BEGIN {print ENVIRON["a"]}' # FOO
gensub()echo aba|awk '{print gensub(/a/,"o",2)}' # abo
gensub() with backrefsecho aba|awk '{print gensub(/(a)/,"o\\1",2)}' # aboa
strftime()awk 'BEGIN{print strftime("%F %T",1)}' # 1970-01-01 00:00:01
length(array)awk 'BEGIN{a[1]=10;a[2]=20;print length(a)}' # 2
asort()awk 'BEGIN{a[1]="z";a[2]="a";asort(a);printf "%s %s\n",a[1],a[2]}' # a z
FNRecho a | awk '{print FNR}' # 1
ARGV arrayawk 'BEGIN{print ARGV[1]}' foo # foo
print (and possibly others?) in for definitionawk 'BEGIN{for(a=1;a<2;print){$0=a"foo";a++}}' # 1foo
$0 contains the last record in the END blockecho foo | awk 'END{print}' # foo

Another compatibility list can be found at shelldorado: