Need to Extract an E-mail Address from a text file.

Posted on 2006-06-01
Last Modified: 2010-04-21
We need to extract e-mail addresses from a text file created by the MDaemon mail server. The userlist.dat is a text file with one user account per line. It does not list the e-mail address in its complete form ( It instead lists them as follows:                             user1   OtherData1a      OtherData1b     OtherData1c    OtherData1d   OtherData1e                             user2   OtherData2a      OtherData2b     OtherData2c    OtherData2d   OtherData2e                             user3   OtherData3a      OtherData3b     OtherData3c    OtherData3d   OtherData3e

Im not sure if the spaces between the domain and the user varies or if it is a tab over. But it appears that they vary based on the length of the domain name, so that the second column is vertically aligned. I think I need to use sed, but I am a complete newbie with regard to sed.

The next step is to output the file into a .map file that postfix will be able to use. I believe we know how to do that once we get a list of the complete emails ( but any hints or shortcuts here would be appreciated.

PS. The .map file will need to look like:     OK     OK

Question by:kishvet
    LVL 45

    Accepted Solution


    Try this:

    awk '{print $2"@"$1}' < datafile

    Where datefile is your file.


    LVL 6

    Assisted Solution

    rm -f .map
    while read f1 f2 f3 f4 f5 f6 f7
    echo $f2@$f1"     OK" >> .map
    done < datafile
    cat .map

    Where datefile is your file.


    Author Comment

    Thanks to both of you for your quick response, in my haste I forgot to mention I was using gawk from the free unixtools for windows.

    I ended up needing to use:

    gawk {print$2\"@\"$1} datafile

    Thanks again for the help and pointing me in the right direction.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Video by: Phil
    This video goes over how to configure and start a jail in FreeBSD.  This video is meant to supplement the article included with this course.

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now