Post Image

Case Insensitive Grep

Grep's default behavior is to be case sensitive, however it is not always the case that you need to match the exact case if your search string. Good thing there is a built in command line switch to make grep ignore case.

 

Syntax

$ grep -i <searchstring> myfile.txt

 

Example

In this example lets assume my file has the following contents

$ cat myfile.txt
This is my file
I dont have a lot of data in this FILE
It is only for demonstration
$

 

And if I run the command above and search for "file" we will see the following output.

$ grep -i file myfile.txt
This is my file
I dont have a lot of data in this FILE
$

 

As you can see it pulls in the first to 2 lines even though the word "file" is in different case.

 



Comments (0)
Leave a Comment