Home > Archive > AWK > November 2004 > Pattern matching
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]
|
|
|
| What am I missing here?
File:
http://standards.ieee.org/regauth/oui/oui.txt
Need: to reveal the company name, based on the first 3 bytes of the MAC
address ($3 of every line where $1 is in xx-xx-xx format, with x=[0-9a-f]
awk script attempted:
awk '$1 ~ /^[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]/i {print
$3}' oui.txt
Instead I am getting $3 of EVERY line, not only those matching pattern ...
What am I missing?!?
TIA,
papi
| |
| Jürgen Kahrs 2004-11-29, 3:58 pm |
| papi wrote:
> What am I missing here?
>
> File:
> http://standards.ieee.org/regauth/oui/oui.txt
>
> Need: to reveal the company name, based on the first 3 bytes of the MAC
> address ($3 of every line where $1 is in xx-xx-xx format, with x=[0-9a-f]
>
> awk script attempted:
>
> awk '$1 ~ /^[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]/i {print
> $3}' oui.txt
>
> Instead I am getting $3 of EVERY line, not only those matching pattern ...
>
> What am I missing?!?
You are missing the fact that - must be escaped.
This one works (tested):
awk '$1 ~ /^[0-9a-f][0-9a-f]\-[0-9a-f][0-9a-f]\-[0-9a-f][0-9a-f]/ {print $3}' oui.txt
| |
| Kenny McCormack 2004-11-29, 3:58 pm |
| In article <30earoF2urcspU1@uni-berlin.de>,
=?ISO-8859-1?Q?J=FCrgen_Kahrs?= <Juergen.KahrsDELETETHIS@vr-web.de> wrote:
....
>
>You are missing the fact that - must be escaped.
>This one works (tested):
>
>awk '$1 ~ /^[0-9a-f][0-9a-f]\-[0-9a-f][0-9a-f]\-[0-9a-f][0-9a-f]/ {print $3}' oui.txt
I don't think that is true. The "-" is not inside of [], so it is just an
ordinary character.
I think the problem has to do with the "i" at the end of the original reg
exp. I recognize that as TAWK syntax for doing a case-insensitive match.
It looks like the OP was trying to use it on a non-TAWK version.
| |
|
| On Mon, 22 Nov 2004 15:19:36 +0100, Jürgen Kahrs wrote:
> papi wrote:
>
> You are missing the fact that - must be escaped.
> This one works (tested):
>
> awk '$1 ~ /^[0-9a-f][0-9a-f]\-[0-9a-f][0-9a-f]\-[0-9a-f][0-9a-f]/ {print $3}' oui.txt
Thank you - I thought I have tried this before, but you know what I
screwed me up that time? The /i at the end! Once I looked at yours I
realized the screw-up ... thx!
| |
| Jürgen Kahrs 2004-11-29, 3:58 pm |
| Kenny McCormack wrote:
> I think the problem has to do with the "i" at the end of the original reg
> exp. I recognize that as TAWK syntax for doing a case-insensitive match.
> It looks like the OP was trying to use it on a non-TAWK version.
I thought the i was a typo.
|
|
|
|
|