Using grep and Ignoring Case (Case Insensitive grep)

grep is a great way to find phrases, words, and characters in text.  One of the biggest stumbling blocks is case – is the word “Hello”, “hello”, “HELLO”, or even “HeLLo”?  All of these are different, and a “grep “Hello”” would only find lines containing the first “Hello” example.

You can, however, exclude case from a grep to make it not case sensitive – simply add -i:

grep -i “Hello” textfile.txt

Alternatively, you could use it in conjunction with cat and tac (Reverse Cat)

cat textfile.txt | grep -i “Hello”

The above will find all lines containing “Hello” in textfile.txt, whether it’s “Hello”, “HELLO”, HElLO”, etc, making it much easier to find instances of “Hello” if you don’t really need to care about case.

 

(Read the article on Wikipedia about Case Sensitivity..)