Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Aug 2008 16:50:31 +0930
From:      Wayne Sierke <ws@au.dyndns.ws>
To:        Martin McCormick <martin@dc.cis.okstate.edu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Regular Expression Trouble
Message-ID:  <1219821631.49053.205.camel@predator-ii.buffyverse>
In-Reply-To: <200808270312.m7R3CJNk076060@dc.cis.okstate.edu>
References:  <200808270312.m7R3CJNk076060@dc.cis.okstate.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 2008-08-26 at 22:12 -0500, Martin McCormick wrote:
> I am trying to isolate only the MAC addresses that appear in
> dhcpd logs.
> For anyone who is interested, the sed construct that should do
> this looks like:
> 
>  sed 's/.*\([[ your regular expression ]]\).*/\1/' 
> 
> The \1 tells sed to only print what matched and skip all the rest.
> 
> 	I am doing something wrong with the regular expression
> that is supposed to recognise a MAC address. MAC addresses look
> like 5 pairs of hex digits followed by :'s and then a 6TH pair
> to end the string.
> 
> 	I have tried:
> 
> [[:xdigit:][:xdigit:][:punct:]
> 
> Sorry. It won't all fit on a line, but there should be a string
> of 5 pairs and the : and then the 6TH pair followed by the
> closing ] so the expression ends with ]]
> 
> One should also be able to put:
> 
> [[:xdigit:][:xdigit:][:punct:]]\{5,5\}[[:xdigit:][:xdigit]]
> 
> Any ideas as to what else I can try?
> 
There have already been good suggestions for you to choose from. I'll
just add my bucketful to the TIMTOWTDI pool:

Since you weren't specific about the format of the log data that you're
attempting to parse (keep that in mind for future questions):

# ifconfig | grep ether
	ether 02:00:20:75:43:34
	ether 00:40:05:10:b9:79
# ifconfig | sed -nE 's/.*ether (([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}).*/\1/p'
02:00:20:75:43:34
00:40:05:10:b9:79
# ifconfig | sed -nE 's/.*ether ([[:xdigit:]:]+).*/\1/p'
02:00:20:75:43:34
00:40:05:10:b9:79
# ifconfig | sed -nE 's/.*ether ([0-9a-f:]+).*/\1/p'
02:00:20:75:43:34
00:40:05:10:b9:79
# ifconfig | sed -nE '/ether/s/.*([0-9a-f:]{17}).*/\1/p'
02:00:20:75:43:34
00:40:05:10:b9:79

And then there's:

# ifconfig | grep ether | cut -d" " -f 2
02:00:20:75:43:34
00:40:05:10:b9:79

But my preference would be:

# ifconfig | awk '/ether/ {print $2}'
02:00:20:75:43:34
00:40:05:10:b9:79


Wayne






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1219821631.49053.205.camel>