Macbernie
Macbernie

Reputation: 1323

Extract email from text file

I try to extract email from text files with:

grep -o ‘[0-9a-zA-Z-_]*@[0-9a-zA-Z-_.]*.[a-zA-Z]*’ infile > outfile.txt

But, the result is:

grep: Invalid range end

I don't know why...

Can someone help ? Thanks

Upvotes: 2

Views: 495

Answers (1)

anubhava
anubhava

Reputation: 784998

Hyphen needs to be first or last character in a character class to avoid escaping. If hyphen appears in the middle then it is considered a range.

Try this grep:

grep -oE '[0-9a-zA-Z_-]+@[0-9a-zA-Z_.-]+\.[a-zA-Z]+' infile > outfile.txt

Also your quoted looked suspicious that I have changed as well.

Upvotes: 3

Related Questions