Anyone who does any coding or text editing in Mac OS X is probably familiar with BBEdit. Bare Bones Software, the company behind BBEdit (and it’s now defunct, sibling TextWrangler) wanted to create a simple but very powerful barebones text editing app. BTW I’ve opened 200MB+ text files with BBEdit without a problem. Since its debut on April 1992, BBEdit has been a staple of power Macintosh users everywhere. But one of the least understood features of BBEdit is its GREP advanced find and replace function.
This article will help you get started with BBEdit GREP advanced find and replace functions and point you in the right direction in case you have more advanced questions.
Who Created GREP?
It was created by legendary programmer Ken Thompson in 1974. Thompson also designed the Unix operating system, the UTF-8 character encoding for the world wide web, as well as several operating systems and programming languages.
What Does GREP Mean?
GREP stands for “Global regular expression print”. GREP allows you to quickly run complex find and replace commands that remove or leave characters.
A Simple BBEdit GREP Find & Replace
The “Save as Web Page” feature in Microsoft Word creates a lot of junk code. It’s ridiculous. Word will create 580+ lines of code before it gets to your first paragraph tag. GREP is the perfect tool to clean up Word’s mess.
The wildcard character combination (.*) will replace anything in its spot. Let’s say for example you have an HTML file with multiple font sizes and you want to make them all the same. Something like this:
span style='font:5.0pt "Times New Roman"'
span style='font:6.0pt "Times New Roman"'
You could run a single GREP that replaces all different font sizes all at once with one size, 7.0pt.
Search: span style='(.*)pt "Times New Roman"'
Replace: span style='7.0pt "Times New Roman"'
Some Great GREP Examples
The useful things that you can do with GREP are endless. Here are a few examples.
Removing Whitespace
Another annoying issue for most programmers is white space. This GREP command will remove all whitespace from the beginning of lines.
Search: ^[ \t]+
Replace:
Mult-Find
Need to search text files for mentions of specific words or phrases? This example searches US President Abraham Lincoln’s famous Gettysburg Address for the words nation, liberty and equality.
egrep 'nation|liberty|equality'
Advanced BBEdit GREP
You can find several great BBedit GREP cheatsheets online with advanced search and replace examples.
Related Articles:
- How To Easily Enable GZIP Compression For Your Website
- How to Force HTTPS By Modifying Your .htaccess File
- When Was The Last Time You Updated Your WordPress Ping List?
- Jimmy Kimmel Demonstrates How Easy It Is To Social Engineer Passwords
Frank Wilson is a retired teacher with over 30 years of combined experience in the education, small business technology, and real estate business. He now blogs as a hobby and spends most days tinkering with old computers. Wilson is passionate about tech, enjoys fishing, and loves drinking beer.
DRocStgSpec
worked like a charm!
Gregory Ledger
How can I do multiple find and replaces on multiple documents. Most instructions show how to do one find and replace on multiple documents at a time in BBEdit. I need to find “phrase 1” and replace it with “phrase A”; find “phrase 2” and replace it with “phrase B”, and so on.
Jeffrey12TA7
I’ve done this before but forget the exact steps. I think you can target a folder of text files or apply your search and replace to all open docs in BBEdit.