Searching for Text While Ignoring Case
Problem
You need to search for a string (e.g., “error”) in a log file, and you want to do it caseinsensitively to catch all occurrences.
Solution
Use the -i option on grep to ignore case:
$ grep -i error logfile.msgs
Discussion
A case-isensitive search finds messages written “ERROR”, “error”, “Error,” as well as ones like “ErrOR” and “eRrOr.” This option is particularly useful for finding words anywhere that you might have mixed-case text, including words that might be capitalized at the beginning of a sentence or email addresses.
See Also
man grep
man regex (Linux, Solaris, HP-UX) or man re_format (BSD, Mac) for the details of your regular expression library
Mastering Regular Expressions by Jeffrey E. F. Friedl (O’Reilly)
Chapter 9’s discussion of the find command and its
-inameoption
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access