• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

How to Make Grep Case Insensitive

Thumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica Wang
Jessica Wang

Jessica Wang

Developer Advocate, Warp

Published: 2/1/2024

About Terminus

Grep is a command used to find words in a string or file. By default, grep is case sensitive. That means all of these search terms would be treated differently:

  • “COMMAND LINE”
  • “Command line”
  • “CoMMand LiNe”

To clarify, if my file contained the string “command line”, none of the above searches would return anything.

Grep Ignore Case

You can add an -i or –ignore-case flag to make grep case sensitive:

grep -i “command line” textfile.txt

grep –ignore-case “command line” textfile.txt

Running Through an Example

1. Run the following in your terminal:

 echo "1) Grep stands for 'global regular expression print'.
 2) grep searches one or more input files for lines that match a given pattern.
 3) GREP is a Linux / Unix command line tool.
 4) gReP originated in the 1970’s.
 5) grep can also be used as a verb - 'I grepped the logs for the words 'error' and 'warning''.
 6) Here is a random line of text that does not mention g r e p at all." > grepFacts.txt

Run in Warp

This command will create a file called grepFacts.txt, put the 6 facts of grep that we’ve written out for you into that file, and save it in your current directory.

See command and expected output here

2. [Feel Free To Skip This Step] If you’re curious or want to verify that this command is actually saved in your file, run cat grepFacts.txt. This command will output all the contents of the file grepFacts.txt.

Thumbnail for Example command being run in the terminalThumbnail for Example command being run in the terminalThumbnail for Example command being run in the terminalThumbnail for Example command being run in the terminal
Example command being run in the terminal

Example command being run in the terminal

See command and expected output here

3. Run grep “grep” grepFacts.txt.

As you can see, this command only matches with the lowercase version of “grep”.

Thumbnail for Example command being run in the terminalThumbnail for Example command being run in the terminalThumbnail for Example command being run in the terminalThumbnail for Example command being run in the terminal
Example command being run in the terminal

Example command being run in the terminal

See command and expected output here

4. Now, run grep -i “grep” grepFacts.txt.

As you can see, this command matches with all instances of “grep”, regardless of case.

See command and expected output here

Conclusion

To recap, the grep command allows you to search for a pattern inside of files, and is case sensitive by default. To make grep case insensitive, all you have to do is add an -i or —ignore-case flag.

As always, you can type man grep into your command line to get the official documentation for grep and all its flags and parameters. If you want to learn more, check out this page for more information on the grep command.

Written by

Thumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica Wang
Jessica Wang

Jessica Wang

Developer Advocate, Warp

Filed Under

Related Articles

Grep Multiple Strings

How to filter lines and extract specific information from the output of commands or text files based on string patterns and regular expressions with grep.

Grep
Thumbnail for Spencer EvansThumbnail for Spencer EvansThumbnail for Spencer EvansThumbnail for Spencer Evans
Spencer Evans

How To Filter The Output of Commands

Learn how to filter and format the output of commands and logs using the grep, awk, uniq, head, and tail commands.

LinuxGrep
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Grep Across Multiple Lines

Guide on several cases of using grep across multiple lines

Grep
Thumbnail for Philip WilkinsonThumbnail for Philip WilkinsonThumbnail for Philip WilkinsonThumbnail for Philip Wilkinson
Philip Wilkinson

Grep In a Directory

Learn how to use grep to search for words and phrases within a directory and all its subdirectories, a specific directory, all files, and other variations.

Grep
Thumbnail for Philip WilkinsonThumbnail for Philip WilkinsonThumbnail for Philip WilkinsonThumbnail for Philip Wilkinson
Philip Wilkinson

Exclude With Grep

Excluding unwanted key terms or directories when using grep

Grep
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Grep Count

Efficiently count lines or occurrences in a file.

Grep
Thumbnail for Philip WilkinsonThumbnail for Philip WilkinsonThumbnail for Philip WilkinsonThumbnail for Philip Wilkinson
Philip Wilkinson

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null