[NCLUG] Regexp Help

Tkil tkil at scrye.com
Thu Jul 25 12:32:41 MDT 2002


>>>>> "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"?  :)

    dmesg | perl -lnwe 'print $1 if /(..:..:..:..:..:..)/'

I think that various flavors of awk have similar capabilities,
something along the lines of

    dmesg | awk '/..:..:..:..:..:../ { print \& }'

(Although that is probably guaranteed to not work as currently
written).

t.



More information about the NCLUG mailing list