[Chapter 27] 27.16 Faking Case-Insensitive Searches
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:44:33Z

#

| Chapter 27 Searching Through Files |

## 27.16 Faking Case-Insensitive Searches

This may be the simplest tip in the book, but it's something that doesn't occur to lots of users.

On many UNIX implementations, the egrep command doesn't support the -i option, which requests case-insensitive searches. I find that case-insensitive searches are absolutely essential, particularly to writers. You never know whether or not any particular word will be capitalized.

To fake a case-insensitive search with egrep, just eliminate any letters that might be uppercase. Instead of searching for Example, just search for xample. If the letter that might be capitalized occurs in the middle of a phrase, you can replace the missing letter with a "dot" (single character) wildcard, rather than omitting it.

Sure, you could do this the "right way" with a command like:

>     % egrep '[eE]xample' *

But our shortcut is easier.

This tip obviously isn't limited to egrep; it applies to any utility that only implements case-sensitive searches, like more.

- ML

27.15 Narrowing a Search Quickly |  | 27.17 Finding a Character in a Column