Date: Wed, 12 Mar 2003 11:08:52 +0000 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: freebsd-questions@FreeBSD.ORG Subject: global regular expression print Message-ID: <20030312110852.GB47126@happy-idiot-talk.infracaninophi> In-Reply-To: <22358.1047465509@www63.gmx.net> References: <22358.1047465509@www63.gmx.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Mar 12, 2003 at 11:38:29AM +0100, Pascal Giannakakis wrote: > Hello, > > i want to extract a word with a regular expressions from a line of text. > Here is what > i currently have: > > grep -c -E 'Interesting ports on [a-zA-Z0-9-.]+ \((.+)\)' > > This will print lines (from nmap), but i need only the 1st match in > parentheses, which > is the IP in this case. What programm would i use to print what grep sees as > \1, > instead of the whole line? There are any number of solutions to this. Here are two possibilities. Assuming that lines of interest in the file always start with 'Interesting ports...' awk '/^Interesting ports on [a-zA-Z0-9-.]+/{ print $5; }' filename Or more generally: perl -ne 'm/Interesting ports on [a-zA-Z0-9-.]+ \((.+)\)/ && print "$1\n";' filename Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way PGP: http://www.infracaninophile.co.uk/pgpkey Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030312110852.GB47126>