grep — Case Insensitive Search

Searching for a pattern in files using grep is case-sensitive by default. Case sensitive means that grep looks for an exact match of your pattern in the related file. This may not surface all matches of the search value because of different writing styles for a given text.

This tutorial shows you how to search a pattern case insensitive in a file to see all matches, regardless the pattern’s writing style.

Ubuntu/Debian Series Overview

Case-Insensitive Search with grep

grep has a --ignore-case flag to ignore the casing when searching for a pattern in a file. This flag tells grep to treat all letters in the pattern and the text in the source file the same, no matter the casing.

You can use the --ignore-case flag or its shorthand -i for case insensitive searching:

grep --ignore-case "pattern" storage/logs/app.log

# use the "-i" shorthand for "--ignore-case"
grep -i "pattern" storage/logs/app.log  

That’s it!


Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.