[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: use grep, egrep to print matched pattern?



On Thu, Jul 18, 2002 at 11:17:00PM +0800, Patrick Hsieh wrote:
> How can grep or egrep pattern in a file and print the pattern only? I
> will not print the whole line. e.g. to search the email address in
> /var/log/mail.log.  I am wondering is it possible to achieve this
> without writing a perl script?

Pipe the output to sed to trim the stuff on either side of the pattern.

grep 'localhost' myfile | sed 's/^\(.*?\)\(localhost\)\(.*?\)$/\2/'

or some such...

-- 
Eric G. Miller <egm2@jps.net>


-- 
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: