From owner-freebsd-current@freebsd.org Wed Aug 16 01:43:08 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 84FF4DDD467 for ; Wed, 16 Aug 2017 01:43:08 +0000 (UTC) (envelope-from t@tomoyat1.com) Received: from mail.tomoyat1.com (tomoyat1.com [133.130.119.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5C55D69B4B for ; Wed, 16 Aug 2017 01:43:07 +0000 (UTC) (envelope-from t@tomoyat1.com) Received: from tomoyat1.com (KD182251122206.au-net.ne.jp [182.251.122.206]) by mail.tomoyat1.com (Postfix) with ESMTPSA id 2504D5F82 for ; Wed, 16 Aug 2017 10:36:38 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tomoyat1.com; s=tomoyat1; t=1502847398; bh=yvum10c/eF9aIYdNI+Td9VF6uRCnQu46WGMozpvrvws=; h=Date:From:To:Subject:Message-ID:From:Sender:To:CC:Subject: Message-Id:Date; b=GH4tw5BCq5cDV+fgyCJPO5TwobVinZuP6PSzWcVyAyEtWTxTnM+krd2MB0BruvwMO PeBQYKmJIpBSljAT5uKzYz2vaK6HO8dfhX5Obe0aifzyLKxiutFPiLlXWDcfkXEVdk rb93ysyBytIM8IRJ/zMq+8MUuZX8oiMPgkF1oA2I= Date: Wed, 16 Aug 2017 10:36:36 +0900 From: Tomoya Tabuchi To: freebsd-current@freebsd.org Subject: Re: BSD awk bug ? Message-ID: <20170816013634.GA8152@tomoyat1.com> Mail-Followup-To: freebsd-current@freebsd.org References: <201708160114.v7G1EkxS079546@kx.openedu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201708160114.v7G1EkxS079546@kx.openedu.org> User-Agent: Mutt/1.7.2 (2016-11-26) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Aug 2017 01:43:08 -0000 On Wed, Aug 16, 2017 at 10:14:46AM +0900, KIRIYAMA Kazuhiko wrote: > admin@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@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@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@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@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@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@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@tbedfpc:~/tmp % uname -a > FreeBSD tbedfpc 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r321597: Thu Jul 27 12:30:57 UTC 2017 root@tbedfc:/usr/obj/usr/src/sys/GENERIC amd64 > admin@tbedfpc:~/tmp % pkg info -aI|grep gawk > gawk-4.1.4_1 GNU version of Awk > admin@tbedfpc:~/tmp % > > > Is this the BSD awk (/usr/bin/awk) bug ? > > --- > KIRIYAMA Kazuhiko > _______________________________________________ > freebsd-current@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" Hello Kiriyama-san, The man page awk(1) says that {m,n} matcning is not supported. The "{5}" part matches the literal sequence of characters it's made out of, I suppose. Someone please correct me if I'm wrong. Regards, Tomoya