Subject: Re: bug in NetBSD and OpenBSD awk
To: None <tech-userlevel@netbsd.org>
From: Geoff Wing <mason@primenet.com.au>
List: tech-userlevel
Date: 04/30/2006 02:27:28
Aleksey Cheusov <cheusov@tut.by> typed:
: NetBSD 3-stable and OpenBSD-3.8 /usr/bin/awk work incorrectly.

Seems to have problems near the end of the pattern.  The input was 145 chars.
Taking off the EOL match $ :

% echo 1_NNIFO 1_PSFR 1_JJFO 1_NNIFO 1_INR 1_NNIMR 1_CC 1_NNING 1_RQ 1_VPLIPF 1_NNIFG 1_JJPG 1_NNIMPG 1_PQINO 1_VPIPN 1_PP3FD 1_JJMA 1_PQMO 1_TC 1_VIIR3 | awk '{ match($0,"^[^_][^ ]*_NNIFO([ ]+[^_]+[^ ]*_(CC|INR|JJFO|JJMA|JJPG|NNIFG|NNIFO|NNIMPG|NNIMR|NNING|PP3FD|PQINO|PQMO|PSFR|RQ|TC|VIIR3|VPIPN|VPLIPF|NOTAG|RQR))*"); print RSTART,RLENGTH }'
1 137

However, putting the last word (1_VIIR3) elsewhere and readding EOL match
gives the correct answer.

% echo 1_NNIFO 1_VIIR3 1_PSFR 1_JJFO 1_NNIFO 1_INR 1_NNIMR 1_CC 1_NNING 1_RQ 1_VPLIPF 1_NNIFG 1_JJPG 1_NNIMPG 1_PQINO 1_VPIPN 1_PP3FD 1_JJMA 1_PQMO 1_TC | awk '{ match($0,"^[^_][^ ]*_NNIFO([ ]+[^_]+[^ ]*_(CC|INR|JJFO|JJMA|JJPG|NNIFG|NNIFO|NNIMPG|NNIMR|NNING|PP3FD|PQINO|PQMO|PSFR|RQ|TC|VIIR3|VPIPN|VPLIPF|NOTAG|RQR))*$"); print RSTART,RLENGTH }'
1 145

This is worth a PR.

Even quirkier, in the original change the 1_VIIR3 to 1_VIRR3 and the match
to VIRR3 and it works.

Which version of nawk on Solaris?  Current awk on NetBSD is the latest nawk.

Regards,
Geoff