how can i search and replace email addresses in a text file?

Joined
May 8, 2009
Messages
3
Reaction score
0
Points
1
i have a text file that i am converting into tab delimited data so that i can import it into a database. the file contains a number of email addresses which are separated by only a preceding blank space, which i want to replace with a tab. it's easy enough to find spaces and replace them with ^t (for a tab) in Word, and i could probably figure out how to search for random email addresses using wildcards, but i can't figure out how to find email addresses and then replace only the space with a tab while leaving the email address intact.

i've found several utilities that strip email addresses out of text, but they just dump them into a new file and everything else is lost.

there must be a simple way to do this. any help will be greatly appreciated.
 
Joined
Mar 30, 2004
Messages
4,744
Reaction score
381
Points
83
Location
USA
Your Mac's Specs
12" Apple PowerBook G4 (1.5GHz)
What you're looking for is a regular expression, and a program that supports them.

I'd suggest you start with this expression, which is basically the one described here but modified so that it instead matches a single space followed by a generic email address, instead of the address itself.
Code:
\ (?=[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)

TextWrangler, which is free, and BBEdit (from the same company) support regular expressions. Open your file, select Search > Find..., paste in the expression and check the "Use Grep" box.
 
OP
L
Joined
May 8, 2009
Messages
3
Reaction score
0
Points
1
What you're looking for is a regular expression, and a program that supports them.

I'd suggest you start with this expression, which is basically the one described here but modified so that it instead matches a single space followed by a generic email address, instead of the address itself.
Code:
\ (?=[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)

TextWrangler, which is free, and BBEdit (from the same company) support regular expressions. Open your file, select Search > Find..., paste in the expression and check the "Use Grep" box.

ok, that did the trick, thanks! now if only i can figure out a way to do the same thing only searching for cities... ;-)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top