As @user3467349 states, regular expressions (regexes) are your (complicated) friend. There's quite a learning curve involved, but it's worth it if you have to do any significant amount of text searching or modification. Many tools support their use (and some use slightly different dialects for their syntax).
If you have access to a Linux system (where it will almost always be installed by default - I expect it must also be installed on OS X, but I don't use that OS) or to a package of tools for your OS (such as Cygwin for Windows), then the place to start is with the grep
(global regular expression print) command. It can find almost anything once you know the basics of regexes. There is also a more obscure command, agrep
, which specializes in finding things "like" other things, but I haven't used it yet.
Another alternative is if you have or can install the programming language perl
on your system (should be available for almost all OSs), it supports it's own dialect of regular expressions which I believe is the most powerful version. It's easy to access the regular expressions feature of perl without knowing a lot about the rest of the language.
If you do have access to a Linux system, then the command
info sed
will bring up instructions for using the sed
tool (which you don't need at the moment). But, if you scroll way down in this help file there's a fairly detailed section explaining how to use regular expressions. This will transfer directly to using them with grep
as well.