extract based on pattern

I have a mail log file and I want to extract some lines belonging to one domain. For example

Input File:

Dec 12 03:15:28 postfix/smtpd[550]: 3F481EB0295: client=unknown[x.x.x.x], sasl_method=PLAIN, sasl_username=abcd@xyz.com
Dec 12 03:22:08 postfix/smtpd[1428]: 60B56EE001D: client=5ad9b9ba.com[x.x.x.x], sasl_method=LOGIN, sasl_username=efgh@abc.com
Dec 12 postfix/smtpd[1428]: 4314FEE0019: client=5ad9b9ba.bb.com[x.x.x.x], sasl_method=LOGIN, sasl_username=xyz@xyz.com

and so on

I want to extract those lines which contains sasl_username=anything@xyz.com. There can be 1000 lines which contains @xyz.com, I want all the lines. Before @xyz.com it can be anything. Hope I am clear.

I am trying with grep and awk commands but could not able to do so. Please suggect any idea

With grep it could be as simple as:

grep xyz.com logfile

What have you tried so far? man grep or search this forum for grep, similar questions have been asked so many times I guess.

If you want to extract all lines which contain @xyz.com then

cat <input file> | grep @xyz.com

Cheers,
Thiru

First thanx for the reply. I think I was not clear in my question. There will be n number of lines besides

Dec 12 03:15:28 postfix/smtpd[550]: 3F481EB0295: client=unknown[x.x.x.x], sasl_method=PLAIN, sasl_username=abcd@xyz.com
Dec 12 03:22:08 postfix/smtpd[1428]: 60B56EE001D: client=5ad9b9ba.com[x.x.x.x], sasl_method=LOGIN, sasl_username=efgh@abc.com
Dec 12 postfix/smtpd[1428]: 4314FEE0019: client=5ad9b9ba.bb.com[x.x.x.x], sasl_method=LOGIN, sasl_username=xyz@xyz.com

which also contains

blah blah from=<abc@xyz.com> blah blah
blah blah from=<def@xyz.com> .........
or it can be like
to=<abc@xyz.com>
to=<def@xyz.com>

But my requirement is I have to extract those lines which have string "sasl_username=anything@xyz.com" from the logs. I hope this time I am clear

I found the solution of my own question...

awk '/sasl_username=/ && /xyz.com/' maillog.txt

This line contains queue id in the 6th field. I am trying to have that value like

awk '/sasl_username=/ && /xyz.com/' maillog.txt | awk 'printf {$6}'

I know this is wrong technique. Can anybody let me know, btw I am searching this forum for my answer.

if you want to get the 6th field and using the SPACE as the delimeter..

awk '/sasl_username=/ && /xyz.com/ {print $6}' maillog.txt

from your example above that would give you

client=unknown[x.x.x.x],
sasl_method=LOGIN,

strange! Is that what you want?

Thanks. My requirement is half solved from your all help. I will return soon with my next queries of second stage related to my program.

Forum rocks !!!!!

I want whole line which contains "sasl_username=name@xyz.com". Where name can be anything ie any name on the planet. And I think the above command is doing that thing. What do you say?