Results 1 to 7 of 7
Hey.
I have a big text file with data,
and i want to extract mail addresses.
How i can do it?...
- 05-17-2007 #1Just Joined!
- Join Date
- Feb 2007
- Posts
- 7
Extract email addresses from big file.
Hey.
I have a big text file with data,
and i want to extract mail addresses.
How i can do it?
- 05-17-2007 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
you can use tools like awk/sed/perl/python etc...
show sample of the file and your expected output.
- 05-17-2007 #3Just Joined!
- Join Date
- Feb 2007
- Posts
- 7
It is a text file with random data inside.
example :
---------------------------------------------------
adfadf dfa asgasagf koko@yahoo.com adfga asdfa aa
sd asdf aazs dump@mail.com adfgf asdff asdfas
sdf sg afdgag rgteggsadf gdfg sdfgsd sdfg sdfgs dfgds
sdfgsd sdgsfg sdfgsf sdfgsf s pips@hotmail.com
ad adfa #4t346 n5635
--------------------------------------------------
- 05-17-2007 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
I augmented your data file:
Then ran this script:Code:% cat data1 adfadf dfa asgasagf koko@yahoo.com adfga asdfa aa sd asdf aazs dump@mail.com adfgf asdff asdfas sdf sg afdgag rgteggsadf gdfg sdfgsd sdfg sdfgs dfgds sdfgsd sdgsfg sdfgsf sdfgsf s pips@hotmail.com ad adfa #4t346 n5635 ad adfa #4t346 n5635 c@c.com o@o.org g@g.gov xxyyzz ad sdfg only-address@ @no-name.com lkjh
To get this:Code:#!/bin/sh # @(#) s1 Demonstrate regular expression for email address. FILE=${1-data1} grep --only-matching -E '[.[:alnum:]]+@[.[:alnum:]]+' $FILE
For a good first approximation ... cheers, drlCode:% ./s1 koko@yahoo.com dump@mail.com pips@hotmail.com c@c.com o@o.org g@g.gov
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 05-17-2007 #5Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:awk ' { for (i=1;i<=NF;i++) { if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ ) { print $i } } }' "file"
- 05-18-2007 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The awk script from ghostdog74 inspired me to simplify the solution:
Run on data file:Code:#!/bin/sh # @(#) s5 Demonstrate most simple regular expression for email address. FILE=${1-data1} tr ' ' '\n' <$FILE | grep '@'
To produce:Code:adfadf dfa asgasagf koko@yahoo.com adfga asdfa aa sd asdf aazs dump@mail.com adfgf asdff asdfas sdf sg afdgag rgteggsadf gdfg sdfgsd sdfg sdfgs dfgds sdfgsd sdgsfg sdfgsf sdfgsf s pips@hotmail.com ad adfa #4t346 n5635 ad adfa #4t346 n5635 c@c.com o@o.org g@g.gov xxyyzz ad sdfg only-address@ @no-name.com lkjh sdfg wacko-one@msu.edu trendnet polk271.sam@fiddlehead.com fdsa wizard4@future.com lucky@911.org
And from there you can filter bad addresses if you have them ... cheers, drlCode:% ./s5 koko@yahoo.com dump@mail.com pips@hotmail.com c@c.com o@o.org g@g.gov only-address@ @no-name.com wacko-one@msu.edu polk271.sam@fiddlehead.com wizard4@future.com lucky@911.org
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 05-18-2007 #7Just Joined!
- Join Date
- Feb 2007
- Posts
- 7
thanx for help dudes


Reply With Quote