JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Ignore case in Linux grep

Author:JIYIK Last Updated:2025/03/20 Views:

In this tutorial, we will learn grepto ignore case in file names using . But first, let's grepstart with .

Use grepto search each file for a pattern. Patterns lists the patterns separated by newlines, grepoutputting each line that matches a pattern.

When used in shell commands grep, the pattern should usually be quoted. If no files are specified, recursive searches check the working directory, while nonrecursive searches read standard input.


grepSyntax in Linux

grepThe syntax of the command is as follows:

$ grep [OPTIONS] PATTERN [FILE...]

Optional items are shown in square brackets.

  • OPTIONS- grepThere are several settings that you can use to customize the way it behaves.
  • PATTERNis a pattern you can use to find something.
  • FILEare the names of one or more input files.

The user running the command must have read permission on the files being searched.


grepCase sensitivity in Linux

grepThe default behavior of commands is case-sensitivity. Case-sensitivity accepts lowercase letters differently than uppercase letters.

For example, the pattern THANOSdoes not match thanos, , Thanosor ThanoS. The text file looks like this:

$ grep "THANOS" thanos.txt

Output:

THANOS

grepUse -ioption to make it case insensitive

grepThe -p option of the command -ican perform a case-insensitive search. For a case-insensitive search, the search pattern THANOSmatches Thanos, , ThaNosor ThanoS.

$ grep -i "THANOS" thanos.txt

Output:

THANOS
thanos
Thanos
ThanoS

ignore-caseThe -w option is -ia more extended variant of the -p option. Hence, we can use the -d command with ignore-casethe -p option grepfor case-insensitive matching.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Check if a file exists using batch processing

Publish Date:2025/03/20 Views:100 Category:OPERATING SYSTEM

This article will demonstrate how to use a batch script to check if a file exists through sample code. Check if a file exists using batch script The general format or syntax of the code to check if a file exists is provided below. IF EXIST

Adding an empty directory in Git

Publish Date:2025/03/20 Views:167 Category:OPERATING SYSTEM

One of the most important things about git is that it only tracks changes to files, not the folders themselves, which can be found here. Directories are automatically added when you add a file in a directory. Also, when you run git add git

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial