Sorry, the whole thing:
car /var/log/maillog | grep -iE "(username|deleted)"
Main Topics
Browse All TopicsSir:
how to use two argument search using the grep command in the linux . i want to find the log of two conditions that is one argument is the username and next the argument is the word DELETED
cat /var/log/maillog | grep username # now in addtion i also want the argument DELETED to be used, please help me on this. thanks in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
savone is correct about this, but to clarify....
To match only lines that have BOTH characteristics you can do something like this...
grep -i username.*deleted /var/log/maillog
if they are in the order username...<otherstuff>...de
grep -i username /var/log/maillog | grep -i deleted
as savone says above, using the -i flag with the grep matches both upper or lower case so "Username USERNAME and username" would all be matched.
to match lines that have EITHER the text username OR the text deleted, you can use the egrep syntax that savone uses
grep -iE "(username|deleted)" /var/log/maillog
or
egrep -i "(username|deleted)" /var/log/maillog
X0.hosts
I don't think Savone is correct. Let assume that you have these records:
username GOOD
username BAD
anotheruser DELETED
username DELETED
Then savone's suggestion will display all four.
But I guess what the asker wants to display *ONLY*
username DELETED
which can not be achieved with OR '|" in the egrep expresion
So the correct one should be:
grep username /var/log/maillog | grep DELETED
Thanks for the reply, Sir my request is i want the log of only one username with the condition DELETED to be accessed.
That is i have an huge log file with many users and also the for example john , he too has many logs but i want to access the log which has the entry of john and the DELETED entry.
Please help me on this.
As I've already told in my note id #25559008 and #25559171 already. The solution I've suggested will work for you. Another alternative is what TinTin has suggested as the second alternative.
I've also presented a test dataset for you in my note #25559171 and shown the solution I've provided would match only
username DELETED
Cheers,
K
We've all pointed out bout the use
grep username /var/log/maillog | grep "DELETED"
will filter all lines containing username in the file /var/log/maillog then it will be further filtered to all lines containing the word DELETED.
So at the end you will be left with all lines containing username and the word DELETED.
This is it. I have presented you with the sample data. You should be getting waht you asked already.
Business Accounts
Answer for Membership
by: savonePosted on 2009-10-13 at 04:46:52ID: 25558927
grep -iE "(username|deleted)"