Re: nawk doesn't match mac addresses with quantifiers
by Ed Morton <morton@[EMAIL PROTECTED]
>
Feb 13, 2008 at 08:27 PM
Robert Langdon wrote:
> Dear Community,
>
> Using quantifiers as shown in the code below doesn't match mac addresses
> from the input file.
>
> Neither...
>
> #!/usr/bin/nawk -f
> /([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])/ {
> print $1
> }
>
> nor
>
> #!/usr/bin/nawk -f
> /[0-9a-fA-F][0-9a-fA-F]:{5}[0-9a-fA-F][0-9a-fA-F]/ {
> print $1
> }
>
> match any line.
I don't believe nawk supports RE intervals (e.g. {5}). GNU awk supports
it if you use the --re-interval option. /usr/xpg4/bin/awk is, I think, a
POSIX awk and so should support it like any POSIX awk would.
> cat input_file.lst
> 00:01:96:b5:bb:ab ANYTEXTA Associated 7 Yes 802.11b
29
> 00:03:66:aa:c2:02 ANYTEXTB Associated 4 No 802.11b
29
> 00:11:cf:df:65:66 ANYTEXTC Associated 4 No 802.11b
29
> 00:f0:f8:00:67:33 ANYTEXTD Associated 4 No 802.11b
29
>
> The code below, without quantifiers, match the mac address properly.
> #!/usr/bin/nawk -f
>
/[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]/
> {
> print $1
> }
>
> Any ideas how to create a proper pattern with quantifiers to match a mac
> address?
gawk --re-interval
'/^([[:xdigit:]][[:xdigit:]]:){5}[[:xdigit:]][[:xdigit:]]/ {
print $1
}'
or:
awk 'BEGIN{x="[[:xdigit:]]"; d=x x; a=d":"d":"d":"d":"d":"d}
$1 ~ a { print $1 }'
Regards,
Ed.