UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 27.15 Narrowing a Search Quickly Chapter 27
Searching Through Files
Next: 27.17 Finding a Character in a Column
 

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


Previous: 27.15 Narrowing a Search Quickly UNIX Power ToolsNext: 27.17 Finding a Character in a Column
27.15 Narrowing a Search Quickly Book Index27.17 Finding a Character in a Column

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System