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



_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to