Ignore case in Linux grep
In this tutorial, we will learn grep
to ignore case in file names using . But first, let's grep
start with .
Use grep
to search each file for a pattern. Patterns lists the patterns separated by newlines, grep
outputting 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.
grep
Syntax
in Linux
grep
The syntax of the command is as follows:
$ grep [OPTIONS] PATTERN [FILE...]
Optional items are shown in square brackets.
-
OPTIONS
-grep
There are several settings that you can use to customize the way it behaves. -
PATTERN
is a pattern you can use to find something. -
FILE
are the names of one or more input files.
The user running the command must have read permission on the files being searched.
grep
Case sensitivity
in Linux
grep
The default behavior of commands is case-sensitivity. Case-sensitivity accepts lowercase letters differently than uppercase letters.
For example, the pattern THANOS
does not match thanos
, , Thanos
or ThanoS
. The text file looks like this:
$ grep "THANOS" thanos.txt
Output:
THANOS
grep
Use -i
option to make it case insensitive
grep
The -p option of the command -i
can perform a case-insensitive search. For a case-insensitive search, the search pattern THANOS
matches Thanos
, , ThaNos
or ThanoS
.
$ grep -i "THANOS" thanos.txt
Output:
THANOS
thanos
Thanos
ThanoS
ignore-case
The -w option is -i
a more extended variant of the -p option. Hence, we can use the -d command with ignore-case
the -p option grep
for 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.
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
在 Linux grep 中忽略大小写
Publish Date:2024/02/04 Views:237 Category:操作系统
-
本教程演示了使用 grep 文档在 Linux 中忽略文件名中的大小写。