greping email addresses

Posted on 2011-04-19
Last Modified: 2012-05-11
I want to grep this line for email addresses.

Apr 19 11:03:04 server sendmail[31328]: p3JI33dt031328: to=<>, delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=38030, [], 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 "", but it misses "".  Can someone fix my grep?

Question by:md168
    LVL 4

    Expert Comment

    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:
    LVL 38

    Expert Comment

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

    Author Comment

    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


    Author Comment

    Correction.  4e4en, your command did find the results, but it includes the brackets.

    LVL 38

    Accepted Solution

    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

    Author Closing Comment

    Perfect. thanks!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
    It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    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.:

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now