Case Insensitive Grep Search
By Pete Freitag
To perform a grep search that ignores case, or is case insensitive, use the -i
option (or --ignore-case
). The grep command is case sensitive by default.
Example Grep Case Insensitive
grep -i bob grep-example-file.txt
The above command will use the grep executable to search the file file.txt
for the string bob
. It will return each line of the file that contains the word string bob
no matter if it is spelled with upper case or lower case letters.
Grep Example File
Here's the contents of the file used in the case insensitive grep search above: grep-example-file.txt
Bob always ignores case. Is bob your name? This line does not have what you want in any case. BOB
Results of grep --ignore-case bob grep-example-file.txt
Here we are going to use the longer, but more descriptive grep command line argument --ignore-case
to accomplish the same task as above:
grep --ignore-case bob file.txt
Which outputs the lines:
Bob always ignores case. Is bob your name? BOB
As you can see both options will solve our task equally well to perform a case insensitive grep file search. The -i
and --ignore-case
grep options should exist on Mac and Linux servers (Ubuntu, RedHat, Amazon, etc)
Case Insensitive Grep Search was first published on August 01, 2005.
If you like reading about grep, bash, or linux then you might also like:
- Counting IP Addresses in a Log File
- Recursively Counting files by Extension on Mac or Linux
- The 15 Most Useful Linux commands
- Creating a Symbolic Link with ln -s What Comes First?