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

Re: use grep, egrep to print matched pattern?



Hello all

> > 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...
i.e.

sed -n 's/.*\([^ ]*@[^ ]*\).*/\1/p' myfile

Uwe

-- 
Uwe Zeisberger

fib where fib = 0 : 1 : zipWith (+) fib (tail fib)


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



Reply to: