Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

greping email addresses

Posted on 2011-04-19
6
Medium Priority
?
366 Views
Last Modified: 2012-05-11
I want to grep this line for email addresses.

Apr 19 11:03:04 server sendmail[31328]: p3JI33dt031328: to=<no-reply@company.com>, delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=38030, relay=otherserver.com. [1.1.1.1], dsn=5.1.1, stat=User unknown

grep -i -e "User unknown"  /jobvite/lmail/lmail3/maillog |  egrep -o '(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})'>> userunknown.txt

My grep will grab "reply@company.com", but it misses "no-reply@company.com".  Can someone fix my grep?

 
0
Comment
Question by:md168
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:4e4en
ID: 35430039
Mostly you should be ok with this one:
grep -o ‘[[:alnum:]+\.\_\-]*@[[:alnum:]+\.\_\-]*’

Open in new window


but you can read more in depth about regex and email here:
http://www.regular-expressions.info/email.html
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 35430053
grep -i -e "User unknown"  /jobvite/lmail/lmail3/maillog |  egrep -o '([\w_\-]+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})'>> userunknown.txt
0
 

Author Comment

by:md168
ID: 35430206
wesley, your command found only one result.  It didn't find many results.
4e4en, your command didn't find anything.

egrep -o '([a-zA-Z]+\-+[a-zA-Z]+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})' did find the no-reply

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:md168
ID: 35430216
Correction.  4e4en, your command did find the results, but it includes the brackets.

Example.
<bob@company.com>
0
 
LVL 38

Accepted Solution

by:
wesly_chen earned 2000 total points
ID: 35430232
grep -i -e "User unknown"  /jobvite/lmail/lmail3/maillog |  egrep -o '([a-zA-Z0-9._%+-]+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})'>> userunknown.txt
0
 

Author Closing Comment

by:md168
ID: 35430237
Perfect. thanks!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question