Date: Wed, 27 Aug 2008 15:45:24 +0200 From: Jonathan McKeown <jonathan@hst.org.za> To: freebsd-questions@freebsd.org Subject: Re: Regular Expression Trouble Message-ID: <200808271545.24509.jonathan@hst.org.za> In-Reply-To: <200808271325.m7RDP28b044255@dc.cis.okstate.edu> References: <200808271325.m7RDP28b044255@dc.cis.okstate.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 27 August 2008 15:25:02 Martin McCormick wrote: > The sed pattern matching system is interesting because I > can think of several similar situations in which the data are > there but there is no guarantee where on a given line it sits > and grep or sed usually will pull in the whole line containing > the desired data which means that one must further parse things > to get what is wanted. Hi Martin Look at grep -o which only outputs the bit that matched the regexp. Using egrep, you can look for exactly two hex digits and a colon, repeated exactly five times, and followed by exactly two hex digits: egrep -o '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}' inputfile will parse inputfile and output all the MAC addresses it finds, one per line (if it finds more than one on an input line, it'll match them and print them on separate output lines), and nothing else. Jonathan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808271545.24509.jonathan>