Home > Archive > AWK > February 2008 > nawk doesn't match mac addresses with quantifiers
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
nawk doesn't match mac addresses with quantifiers
|
|
| Robert Langdon 2008-02-13, 9:58 pm |
| 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.
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?
Thanks in advance.
Robert
| |
| Ed Morton 2008-02-13, 9:58 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.
| |
| Robert Langdon 2008-02-15, 3:59 am |
| On 2008-02-14 03:27:05 +0100, Ed Morton <morton@lsupcaemnt.com> said:
>
> 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.
>
> 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.
Dear Ed,
You are fully right. The standard awk in the default path /usr/bin on
Solaris seems to be a non gawk version. Using /usr/xpg4/bin/awk works
fine with the quantifier {5}. Nowadays, gawk should be the default
version on a modern Unix, but hey, without such capers Solaris wouldn't
be Solaris.
So, many many thanks for your swift hint.
Cheers,
Rob.
| |
| Kenny McCormack 2008-02-15, 6:59 pm |
| In article <2008021509143116807-not@homenet>,
Robert Langdon <not@home.net> wrote:
....
>fine with the quantifier {5}. Nowadays, gawk should be the default
>version on a modern Unix, but hey, without such capers Solaris wouldn't
>be Solaris.
Solaris is not a modern Unix. Not that there is anything wrong with that.
It is and always was a pioneer. They created the whole thing, but then,
like all pioneers, became a captive of its own legacy.
| |
| usenetpersongerryt@gmail.com 2008-02-15, 6:59 pm |
| On Feb 15, 6:09 am, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
> In article <2008021509143116807-not@homenet>,
> Robert Langdon <n...@home.net> wrote:
Obviously something both of you know nothing about.
[color=darkred]
> Solaris is not a modern Unix. Not that there is anything wrong with that.
Define a "modern Unix" as you put it. You mean a UNIX with legacy
things like:
free access to source and other downloadables like a really excellent
C C++ fortran compiler, eco-friendly servers with 8 core CPUs, zones,
projects, roles, fault management,
firmware hypervision, brandz, zfs, dtrace, etc etc
Not that this has anything to DO with awk..
> It is and always was a pioneer. They created the whole thing, but then,
> like all pioneers, became a captive of its own legacy.
We'll see. So far all I read from you two stooges is pure OT FUD and
myth.
Ed provided a solution in POSIX compliant awk on Solaris. Thank you
Ed.
| |
| Kenny McCormack 2008-02-15, 6:59 pm |
| In article <54c23b43-6efe-4b17-8628-cf84815bf731@h11g2000prf.googlegroups.com>,
<usenetpersongerryt@gmail.com> foamed:
....
>Not that this has anything to DO with awk..
True.
>
>We'll see. So far all I read from you two stooges is pure OT FUD and myth.
Hit a nerve, did I?
It was certainly not my intent to adversely affect your blood pressure so.
|
|
|
|
|