BSD awk bug ?
KIRIYAMA Kazuhiko
kiri at kx.openedu.org
Wed Aug 16 01:14:56 UTC 2017
admin at tbedfpc:~/tmp % ll
total 12
-rw-r--r-- 1 admin admin 235 Aug 16 10:01 regex-1.sh
-rw-r--r-- 1 admin admin 236 Aug 16 10:01 regex-2.sh
-rw-r--r-- 1 admin admin 260 Aug 16 10:01 regex.sh
admin at tbedfpc:~/tmp % cat regex.sh
#!/bin/sh
data='1 2 3 4 5 6
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4
1 2 3'
IFS=$'\n'
for datum in $data; do
if echo "$datum" | egrep -q '^([^[:space:]]+[[:space:]]+){5}'; then
echo "$datum"
else
echo "Not 6 components! : \"$datum\""
fi
done
admin at tbedfpc:~/tmp % sh ./regex.sh
1 2 3 4 5 6
Not 6 components! : "1 2 3 4 5"
1 2 3 4 5 6
1 2 3 4 5 6
Not 6 components! : "1 2 3 4"
Not 6 components! : "1 2 3"
admin at tbedfpc:~/tmp % cat regex-1.sh
#!/bin/sh
_f_awk='
{
if ($0 ~ /^([^[:space:]]+[[:space:]]+){5}/) {
print $0
} else {
print "Not 6 components! : \"" $0 "\""
}
}'
data='1 2 3 4 5 6
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4
1 2 3'
echo "$data" | awk "$_f_awk"
admin at tbedfpc:~/tmp % sh ./regex-1.sh
Not 6 components! : "1 2 3 4 5 6"
Not 6 components! : "1 2 3 4 5"
Not 6 components! : "1 2 3 4 5 6"
Not 6 components! : "1 2 3 4 5 6"
Not 6 components! : "1 2 3 4"
Not 6 components! : "1 2 3"
admin at tbedfpc:~/tmp % cat regex-2.sh
#!/bin/sh
_f_awk='
{
if ($0 ~ /^([^[:space:]]+[[:space:]]+){5}/) {
print $0
} else {
print "Not 6 components! : \"" $0 "\""
}
}'
data='1 2 3 4 5 6
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4
1 2 3'
echo "$data" | gawk "$_f_awk"
admin at tbedfpc:~/tmp % sh ./regex-2.sh
1 2 3 4 5 6
Not 6 components! : "1 2 3 4 5"
1 2 3 4 5 6
1 2 3 4 5 6
Not 6 components! : "1 2 3 4"
Not 6 components! : "1 2 3"
admin at tbedfpc:~/tmp % uname -a
FreeBSD tbedfpc 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r321597: Thu Jul 27 12:30:57 UTC 2017 root at tbedfc:/usr/obj/usr/src/sys/GENERIC amd64
admin at tbedfpc:~/tmp % pkg info -aI|grep gawk
gawk-4.1.4_1 GNU version of Awk
admin at tbedfpc:~/tmp %
Is this the BSD awk (/usr/bin/awk) bug ?
---
KIRIYAMA Kazuhiko
More information about the freebsd-current
mailing list