Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Pattern matching
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

Report this thread to moderator Post Follow-up to this message
Old Post
papi
11-29-04 08:58 PM


Re: Pattern matching
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

Report this thread to moderator Post Follow-up to this message
Old Post
Jürgen Kahrs
11-29-04 08:58 PM


Re: Pattern matching
In article <30earoF2urcspU1@uni-berlin.de>,
examnotes  <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.t
xt

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.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
11-29-04 08:58 PM


Re: Pattern matching
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!


Report this thread to moderator Post Follow-up to this message
Old Post
papi
11-29-04 08:58 PM


Re: Pattern matching
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Jürgen Kahrs
11-29-04 08:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:52 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.