Re: use grep, egrep to print matched pattern?
On Thu, Jul 18, 2002 at 06:02:28PM +0200, Uwe Zeisberger wrote:
> 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
Oh, a mistake, use:
sed -n 's/.* \([^ ]*@[^ ]*\).*/\1/p' myfile
else Output _can_ contain
sdajfh user@domain.tld
(the solution of martin has the same prob)
Uwe
--
Uwe Zeisberger
$ dc << EOF
[1++2Q]sa[+1-1 2Q]sb[syd1-rly1-]sc[rd0=ard0=blcx]sd[ldxz1<e]se24872P3dn11296P4dn689978656Plexf
EOF
--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to: