[NCLUG] Regexp Help

Michael Dwyer mdwyer at sixthdimension.com
Thu Jul 25 13:07:49 MDT 2002


Tkil wrote:
>>>>>>"Michael" == Michael Dwyer <mdwyer at sixthdimension.com> writes:
> Michael> This snippet returns anything in the kernel ring buffer that
> Michael> looks like a MAC address:
> Michael>     dmesg | grep  ..:..:..:..:..:..
> Michael> So I get lines like:
> Michael>     foomatic.c Foo Ethernet Driver at 31:33:7b:ee:fc:ab. Initialized.
> Michael> How, using only tools like grep, awk, sed, printf, cut, etc,
> Michael> can I get ONLY the mac address?  How do I get output like:
> Michael>    31:33:7b:ee:fc:ab
> Michael> Am I missing something totally obvious?
> 
> Um, "use perl"?  :)

I wish I could...  Disk space being rare, perl isn't allowed.  Besides, 
now I can throw on a holier-than-thou cloak of old-farthood and 
admonish, "When I was your age, we had to edit all the files with a row 
of switches and some nixie tubes!"

> I think that various flavors of awk have similar capabilities,
> something along the lines of
>     dmesg | awk '/..:..:..:..:..:../ { print \& }'

Yeah, I couldn't find any way to do that short of this snippet:

    { print substr($0,match($0,"..:..:..:..:..:.."),RLENGTH); }

It works, but I still wonder if I'm missing something obvious (like a -o 
flag on grep. :)




More information about the NCLUG mailing list