- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: pulling email from file via script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 06:51 AM
12-11-2003 06:51 AM
I have a file with about 3000 lines with email addresses at various places in the lines and I want to just pull out the email address and put them in a file.
The file looks like this:
with SMTP id <0HPN00HGJ9OLLS@l-daemon> for Minden@shaw.ca; Tue,
(reason: 554 delivery error: dd This user doesn't have a swbell.net account (kar
iak@swbell.net) [-9] - mta825.mail.sc5.yahoo.com)
451
5.1.0 - Unknown address error 550-'Invalid recipient:
5.1.0 - Unknown address error 550-'Invalid recipient:
550 5.0.0
550 5.0.0
550 5.0.0
550 5.1.1 <98c093@sirjamessmiths.cornwall.sch.uk>... User unknown
550 5.1.1
I want to have just the email address from each line, and can deal with the <, (, ... etc. myself. So even if I ended up with
test@test.com
in the file that would be ok.
TIA,
Sean
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:00 AM
12-11-2003 07:00 AM
Re: pulling email from file via script
To filter only the lines that contains the e-mail address use,
grep '\>@\<' filename
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:02 AM
12-11-2003 07:02 AM
Re: pulling email from file via script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:06 AM
12-11-2003 07:06 AM
Re: pulling email from file via script
grep -i "@" < input_file|tr -d" " "\n"|tr -d "\<" "\n"|tr -d "\>" "\n"|grep -i "@"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:31 AM
12-11-2003 07:31 AM
Re: pulling email from file via script
That doesn't work on my system:
# cat fg3 |tr -d" " "\n"
tr: illegal option --
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
tr [ -cd | -cs | -d | -s ] [-A] String1
running 11i.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:41 AM
12-11-2003 07:41 AM
Re: pulling email from file via script
And the email addresses are not always deliminated by <>.
I was wondering if there was any way to simply key in on the @ and then grab everything up to the white space both before and after the @ sign.
Some lines may have more than one email address in them as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:41 AM
12-11-2003 07:41 AM
Re: pulling email from file via script
grep '\>@\<' filename | awk -F"<" '{print $2}' | awk -F">" '{print $1}'
Will extract exactly the mail IDs.
Enjoy,
Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:08 AM
12-11-2003 08:08 AM
SolutionA real dirty one. But works !!!
for i in `cat filename`; do echo $i; done |grep @
The output is,
[root@lnxsrv tmp]# for i in `cat 123`; do echo $i; done |grep @
<0HPN00HGJ9OLLS@l-daemon>
Minden@shaw.ca;
iak@swbell.net)
<98c093@sirjamessmiths.cornwall.sch.uk>...
[root@lnxsrv tmp]#
However you will have to remove <, >, and ...s.
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:10 AM
12-11-2003 08:10 AM
Re: pulling email from file via script
-----------------------------------
with SMTP id <0HPN00HGJ9OLLS@l-daemon> for Minden@shaw.ca; Tue,
(reason: 554 delivery error: dd This user doesn't have a swbell.net account (kar
iak@swbell.net) [-9] - mta825.mail.sc5.yahoo.com)
451
5.1.0 - Unknown address error 550-'Invalid recipient:
5.1.0 - Unknown address error 550-'Invalid recipient:
550 5.0.0
550 5.0.0
550 5.0.0
550 5.1.1 <98c093@sirjamessmiths.cornwall.sch.uk>... User unknown
550 5.1.1
-----------------------------------
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:18 AM
12-11-2003 08:18 AM
Re: pulling email from file via script
try this:
while read LINE
do
EMAIL=`expr "${LINE}" : ".*<\([0-9,a-z,A-Z,.]*@[0-9,a-z,A-Z,.]*\)>.*"`
echo ${EMAIL}
done < file
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:41 AM
12-11-2003 08:41 AM
Re: pulling email from file via script
That was a nice script but it seems to be missing out few e-mail IDs.
-------------------------------------------------------------------
[root@lnxsrv tmp]# while read LINE; do EMAIL=`expr "${LINE}" : ".*<\([0-9,a
-z,A-Z,.]*@[0-9,a-z,A-Z,.]*\)>.*"`; echo ${EMAIL}; done < file
jweirdeyes@wmconnect.com
ddphoto@sympatico.ca
iimiij@sympatico.ca
fhutsler@mbox1.greenapple.com
lisab@netrover.com
robbieduncan@optusnet.com.au
98c093@sirjamessmiths.cornwall.sch.uk
ASPROMATIS@RHO.FORTHNET.GR
-------------------------------------------------------------------
[root@lnxsrv tmp]# for i in `cat file`; do echo $i; done |grep @
arejayg@msys.net>;
<0HPN00HGJ9OLLS@l-daemon>
Minden@shaw.ca;
iak@swbell.net)
<98c093@sirjamessmiths.cornwall.sch.uk>...
[root@lnxsrv tmp]#
-------------------------------------------------------------------
For instance iak@swbell.net is not listed in the o/p of your script.
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:06 PM
12-11-2003 07:06 PM
Re: pulling email from file via script
how about this approach:
#!/usr/bin/sh
# carve out emailad
while read LINE
do
CUT_END=$(echo ${LINE#*@)
CUT_END=$(echo "$CUT_END"|awk '{print $1}')
CUT_BEGIN=$(echo ${LINE%%@*)
CUT_BEGIN=$(echo "$CUT_BEGIN"|awk '{print $NF}')
echo "${CUT_BEGIN}@${CUT_END}"
done <$1
with your input file as $1.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:29 PM
12-11-2003 07:29 PM
Re: pulling email from file via script
perl -n -e 'print /.*\b(.+@[A-z,.]+)/;print "\n"' testfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 07:35 PM
12-11-2003 07:35 PM
Re: pulling email from file via script
perl -n -e 'print /.*\b([0-z]+@[0-z,.]+)/;print "\n"' testfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:03 PM
12-11-2003 08:03 PM
Re: pulling email from file via script
sed -n 's|^.*<\(.*@.*\..*\)>.*$|\1|p'
A mail address need to be enclosed in the brackets and needs at least 1 dot after the @
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:09 PM
12-11-2003 08:09 PM
Re: pulling email from file via script
yes, you are right, I overlooked that emails could be enclosed by (.
This should fix it.
have fun,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:10 PM
12-11-2003 08:10 PM
Re: pulling email from file via script
sed -n 's|^.* \([^ ]*@[^ ]*\.[^ ]*\) .*$|\1|p'
This only relies now on the mail address being enclosed by spaces... So brackets etc. will be printed too.