Reputation: 3452
I want to extract all email address from csv file. how to do this action. by the way the location of the email is not organized by column or by row.
in fact there is no regular format, but I give you an example
"bla bla bla bla Website: www.mysite.com ; Email: [email protected]";usa;
so the question is how to extract the email address from this sentence ?
Upvotes: 0
Views: 3932
Reputation: 3452
extract email adsress from folder full of csv file; just using perl
cat *.csv > all.csv
perl -wne'while(/[\w\.\-]+@[\w\.\-]+\w+/g){print "$&\n"}' all.csv | sort -u > output.txt
Upvotes: 0
Reputation: 3452
thank for all; I found the correct answer for my question, it is :
grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" file.csv | sort -u > email_list
Upvotes: 10
Reputation: 77339
Please adjust the regular expression if needed (\S+@\S+
probably too simple):
grep -o -P '\S+@\S+' input.csv
From man grep
:
-o, --only-matching
Print only the matched (non-empty) parts of a matching line,
with each such part on a separate output line.
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression (PCRE, see below).
This is highly experimental and grep -P may warn of unimplemented features.
To sort and skip duplicates:
grep -o -P '\S+@\S+' input.csv | sort -u
Upvotes: 3