Finding an email address


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding an email address
# 1  
Old 09-17-2008
Finding an email address

Hi all,

I have a file with X number of lines.
Somewhere within each line will be an email address following the format:

<telephone_number>@domain.net

Each line is not a set length and there are no delimiters to work with.

I want to write a script that extracts the telephone number from each line and writes this extract to a file.

I think the key to this is the '@' symbol, but i've had no luck constructing an awk command to extract the string (either 10 or 11 integers in length as per UK format) from immediatley before the @.

Can anyone help?

All assistance is much appreciated.

Kind Regards
# 2  
Old 09-17-2008
Code:
grep \@ fileIN | tr -s ' ' '\n' | grep \@ | awk -F"@" '{print $1}' >fileOUT

I haven't done any of the 10/11 digit magic...
# 3  
Old 09-17-2008
Code:
 grep [0-9]*\@[A-Za-z0-9]*\.[A-Za-z0-9]* fileIN >fileOUT

Oh this will just out put the while ###@xxx.xx , guess I should read better.

Here this will work
Code:
grep [0-9]*\@[A-Za-z0-9]*\.[A-Za-z0-9]* fileIN | sed 's/\@[A-Za-z0-9]*\.[A-Za-z0-9]*//' >fileOUT

ASSuming there are no @s anywhere else in the file this will work: (AND all emails it finds are ONLY phone numbers)
Code:
grep @ fileIN | sed 's/\@[A-Za-z0-9]*\.[A-Za-z0-9]*//'  >fileOUT


Last edited by Ikon; 09-17-2008 at 02:29 PM..
# 4  
Old 09-17-2008
Thanks avronius and Ikon, great stuff.

I also managed to get it working with this:

Code:
grep -o "[[:graph:]]*@[[:graph:]]*" input_file | awk -F"@" '{print $1}' > output_file

Thanks alot Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding if my IP address belongs in a Class C group

I need help with a tcl code. I have a variable "myIP" which reads IP address from socket. How do I use regex to find out if it belongs to a group for e.g., 50.65.75.240/28 or 50.65.75.128/25 etc. (2 Replies)
Discussion started by: ampak
2 Replies

2. Forum Support Area for Unregistered Users & Account Problems

Cant use certain email address

I tried to re-register using my new email address which is <firstname>@<surname>.me But it never sent out the email confirmation. I had to hit the back button and use my gmail address instead and it came through instantly. Is there a problem with using .me addresses? (1 Reply)
Discussion started by: frustin
1 Replies

3. Forum Support Area for Unregistered Users & Account Problems

Change email address

How can I change email address registered with my unix.com account (1 Reply)
Discussion started by: hiten.r.chauhan
1 Replies

4. Filesystems, Disks and Memory

Finding IP address of the system hosting an NAS

Hi, On Solaris 5.8 when I run the command df -F nfs one of the outputs I am getting is: pun-filer-01:/vol/Unix/punehome/vineetd out of which "pun-filer-01" is hostname of the machine on which the NAS device is hosted and /vol/Unix/punehome/vineetd is the mount point. I am interested in... (2 Replies)
Discussion started by: vineetd
2 Replies

5. UNIX for Dummies Questions & Answers

Finding an IP address

Using either % nslookup www.computerhope.com or % host www.computerhope.com Is there a way to single out only the IP address and not all the other information that these commands return by using the options or something of this nature. For Example I would like to do this Echo... (1 Reply)
Discussion started by: slim1509
1 Replies

6. UNIX for Dummies Questions & Answers

Finding IP address of the workstation

Hi, I have the following requirement. I want to configure in the .profile file of my user id in such a way that it loads a particular set of command when i log in from a particular machine and another set when i log into the server from a different machine. What is the command to get the... (1 Reply)
Discussion started by: Vijay Srinivasa
1 Replies

7. UNIX for Dummies Questions & Answers

Send email where # is in the email address - Using Unix

Hi All, How do I send an email using malix where email address contains a #. I have a email address like this : #test@test.com I want to send email like malix -s "TEST" #test@test.com < SOMEFILE I tried \# but doesn't work. Please let me know how we can achieve this? I am in... (1 Reply)
Discussion started by: jingi1234
1 Replies

8. UNIX for Dummies Questions & Answers

Finding LocalHost IP Address

I am writing a program that need to be run on several machines. I am running UNIX and wanted to know if there is a command similar to ipconfig (in DOS) that would return the IP Address of the machine that I am working on. (Not just the loopback address of 127.0.0.1). (1 Reply)
Discussion started by: hazard0007
1 Replies

9. IP Networking

Finding an x25 address for a server

I am trying to find the x25 address of a server. Presumably this is stored in some sort of config file - and while I can find the IP and OSI addresses - I cannot work out where to find the x25 address.....any ideas? (Unix on Solaris) (1 Reply)
Discussion started by: peter.herlihy
1 Replies
Login or Register to Ask a Question