BBEdit Grep

July 10, 2012 by Gabe | [mmd] |

I'm not very good with regular expressions, but I do know Grep is powerful magic. As part of my exciting weekend I needed to go through a 36K line XML file and change all of the URL's from this format:

http://www.macdrifter.com/2011/09/when-is-an-ipad-enough-for-notes/

To this format where the ending forward slash is replaced by ".html"

http://www.macdrifter.com/2011/09/when-is-an-ipad-enough-for-notes.html

BBEdit to the rescue. Not only was BBEdit the only text editor that could open the 254MB file but the Find and Replace tools support regex. The setup is simple:

Notice that the "Replace" function recognizes the Grep tokens for replacement. In this case "\1" is the URL before the last forward slash. It represents the first regex in parentheses. Hitting "Replace" does exactly what I wanted. BBEdit is good stuff.

This does fail if multiple URL's are on the same line. Like I said, I'm not that good with regex.

blog comments powered by Disqus