[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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

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 (user1@domain1.com). It instead lists them as follows:

domain1.com                             user1   OtherData1a      OtherData1b     OtherData1c    OtherData1d   OtherData1e
domain2.com                             user2   OtherData2a      OtherData2b     OtherData2c    OtherData2d   OtherData2e
domain2.com                             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 (user1@domain1.com) but any hints or shortcuts here would be appreciated.


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

user1@domain1.com     OK
user2@domain2.com     OK
etc.


-Donald
0
kishvet
Asked:
kishvet
2 Solutions
 
Kent OlsenData Warehouse Architect / DBACommented:

Try this:

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


Where datefile is your file.

Kent

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

Where datefile is your file.

Bira
0
 
kishvetAuthor Commented:
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.

-Donald
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now