bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Regular Expressions] AWK not working according to specification giv


From: Micah Cowan
Subject: Re: [Regular Expressions] AWK not working according to specification given in manual
Date: Fri, 20 Mar 2009 22:53:53 -0700
User-agent: Thunderbird 2.0.0.19 (X11/20090105)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kalidas Yeturu wrote:
> Hi
> 
> echo "1S7Q
>    abckd" | awk '/[:alnum:]{4}/{print $0}'
> 
> Does NOT OUTPUT 1S7Q as expected

Depends on whose expectations we're talking about.

First of all, you meant [[:alnum:]], not [:alnum:].

Second, while POSIX does indeed require your (ammended) statement to
match the first line, historical awk practice preceding POSIX did not
have intervals (the "{4}"), so in the interest of not breaking all the
existing scripts, GNU awk does not follow POSIX by default: you must
specify either --posix or --re-interval (this is in the manual).

Note that the second line will also match, since you don't anchor the
expression to the start of the line with a "^".

Note that the POSIX character classes, such as [:alnum:], does not have
particularly wide support among awk implementations. For instance, mawk,
which is the default awk on Ubuntu, does not support them. Portable code
should avoid them, along with the intervals ("{4}").

- --
HTH,
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
Maintainer of GNU Wget and GNU Teseq
http://micah.cowan.name/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknEgPEACgkQ7M8hyUobTrFanwCcDaJJpfVtXWZOVvmaEM+oVA/m
xjAAoIaEbGdJuH+ll6j2Sxc4ntDjFpM5
=HZwK
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]