I use grep quite a bit in BBEdit for simple replacement but nothing especially complicated. Recently I have been cleaning up my PHP error log after installing PHP 8.1 after years of using PHP 5. Most of the changes were easy, just initializing variables before use. Some were more complicated like getting rid of braces in array calls. And some took a while to figure out, like accessing session variables. I also had some beta code that I didn’t want to address yet. So the grep commands I settled on were variants of this.
grep -ihrw '/var/log/php_error.log' -e 'locutour' | grep -v '$_SESSION' | grep -v 'array'
-i is case insensitive
-h supresses the file name, which I already know
-r is a recursive flag, which I don’t need in this particular instance
-w matches the whole word
-e is followed by the pattern or patterns, in this case looking for just one website. You can include multiple patterns with multiple instances of -e e.g. -e 'locutour' -e 'wellgolly'
I didn’t feel like dealing with session and array warnings on the first pass, so I piped the results to a grep with the -v flag to remove those warnings.
Because it is a pipe, you can redirect it to a file instead of the screen and I did that when looking for words in a file of Nero Wolfe books when compiling a database of my favorite Nero Wolfe words. In this case I was looking for all of the adverbs that Archie used when describing how someone spoke. I piped it to a file and used BBEdit to clean it up so that I only had one instance of each.
grep -ihrw the-complete-NW-modified.txt -e 'said.*ly\.' > saidly.txt