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

grep \@ fileIN | tr -s ' ' '\n' | grep \@ | awk -F"@" '{print $1}' >fileOUT

I haven't done any of the 10/11 digit magic...

 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

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)

grep @ fileIN | sed 's/\@[A-Za-z0-9]*\.[A-Za-z0-9]*//'  >fileOUT

Thanks avronius and Ikon, great stuff.

I also managed to get it working with this:

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

Thanks alot :b: