From owner-freebsd-questions@FreeBSD.ORG Wed Aug 27 13:42:40 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4FF0E106564A for ; Wed, 27 Aug 2008 13:42:40 +0000 (UTC) (envelope-from jonathan@hst.org.za) Received: from hermes.hst.org.za (onix.hst.org.za [209.203.2.133]) by mx1.freebsd.org (Postfix) with ESMTP id 661798FC18 for ; Wed, 27 Aug 2008 13:42:38 +0000 (UTC) (envelope-from jonathan@hst.org.za) Received: from sysadmin.hst.org.za (sysadmin.int.dbn.hst.org.za [10.1.1.20]) (authenticated bits=0) by hermes.hst.org.za (8.13.8/8.13.8) with ESMTP id m7RDamgr048589 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 27 Aug 2008 15:36:48 +0200 (SAST) (envelope-from jonathan@hst.org.za) From: Jonathan McKeown Organization: Health Systems Trust To: freebsd-questions@freebsd.org Date: Wed, 27 Aug 2008 15:45:24 +0200 User-Agent: KMail/1.9.7 References: <200808271325.m7RDP28b044255@dc.cis.okstate.edu> In-Reply-To: <200808271325.m7RDP28b044255@dc.cis.okstate.edu> X-Face: $@VrUx^RHy/}yu]jKf/<4T%/d|F+$j-Ol2"2J$q+%OK1]&/G_S9(=?utf-8?q?HkaQ*=60!=3FYOK=3FY!=27M=60C=0A=09aP=5C9nVPF8Q=7DCilHH8l=3B=7E!4?= =?utf-8?q?2HK6=273lg4J=7Daz?=@1Dqqh:J]M^"YPn*2IWrZON$1+G?oX3@ =?utf-8?q?k=230=0A=0954XDRg=3DYn=5FF-etwot4U=24b?=dTS{i X-Spam-Score: -4.295 () ALL_TRUSTED,AWL,BAYES_00 X-Scanned-By: MIMEDefang 2.61 on 209.203.2.133 Subject: Re: Regular Expression Trouble X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Aug 2008 13:42:40 -0000 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