Grepping with text editors

Text editors are special programs that focus on, well, text. Not formatting, not creating magazines or reports, but text. The best of them can do all sorts of crazy things, but one of the main features is “GREP searching.”

GREP searching makes my life much easier, both in surveys and here at Allpar.

GREP searching is essentially using “regular expressions,” like “any number,” or “any text,” or “anything starting with <tr and ending with >.” Using GREP search-and-replace, with, say, TextWrangler or BBEdit (there are programs for Macs, Windows, and Linux), you can do amazing things.

For example, I recently had to convert a survey table for mobile use. I quickly wrote a search-and-replace expression that looks for the start of a question in a table, then, instead of letting that cell close, makes the cell span the rest of the table, closes the row, opens a new row, and adds a blank cell — so that now you have questions with the choices, indented, below it, and you can see the whole table on a cellphone. The little script just a little time to write, and I saved it, so it can be used every month, saving around 15 minutes of drudge work, and preventing errors. (You can see most of it below).

That’s just one example.


There are things I can easily do at Allpar thanks to text editors and, for that matter, macros in general. Formatting tables is done through a Javascript in Dreamweaver, from back in the days when Macromedia encouraged that (now Dreamweaver is owned by Adobe and while they support it, they don’t encourage it, and the first answer to any problem is “reinstall everything, deleting all your customizations.”)

I get material from all sorts of sources, and often I need to clean up special characters mangled in e-mail or forms, or line endings, or other problems. There are scripts for all of this. (As far as I can tell, GREP comes from a UNIX-and-Linux program of the same name.)

It took a lot of time to master GREP searches, or at least it took me a lot of time to master it, but now, I use it all the time, for all sorts of reasons — to get rid of Microsoft junk in html files, to convert from tab-delimited files to html tables, to reformat, to replace words or patterns in thousands of files at once, and all sorts of other things.

Text editors are incredibly handy. GREP search-and-replace is just one of their benefits. If you do a lot of work on a computer, and don’t have one now, it’s worth getting a free one to play with — and, after you’ve saved enough time to justify it, shell out some money to buy one.

Leave a Reply

Your email address will not be published. Required fields are marked *