We help IT Professionals succeed at work.
Get Started

Dump email addresses out of flat files using Regex and sed

Last Modified: 2013-12-26
I've got a folder full of csv and text files that I need to grab all of the email addresses out of. These files are stored on a linux server so I'd like to be able to use the command line or a script to do the following:
For each file in a folder (whether it's a CSV file, tab delimited, or | delimited)
   Search each line for the email address, and send all of those lines to a new file

chris@gmail.com, Chris, Last name, phone
1234, chris@gmail.com, Chris, Last Name, phone

ouput to File1-emails.csv:

"chris@gmail.com", Chris, Last name, phone

ouput to File2-emails.csv:

chris@gmail.com|chris|last  name| phone

ouput to File3-emails.txt:

The point here is, I'd like the script to be able to run in files of different formats.
Watch Question
Most Valuable Expert 2014
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE