grep 不区分大小写
grep
is very useful too to match and find phrases, words and characters in test. One of the most used situation is using grep
case sensitive or case insensitive. In this tutorial we will examine different examples. We have all ready examined grep
in the following tutorial.
grep
在测试中匹配和查找短语,单词和字符时也非常有用。 最常用的情况之一是使用grep
区分大小写或不区分大小写。 在本教程中,我们将研究不同的示例。 在下面的教程中,我们已经准备好检查grep
。
Linux grep Command Tutorial with Examples
区分大小写(Case Sensitive)
We will start with the default behavior of the grep
command which is case sensitive. In this example we will search for ismail
in /etc/passwd
.
我们将从区分大小写的grep
命令的默认行为开始。 在此示例中,我们将在/etc/passwd
搜索ismail
。
$ grep "ismail" /etc/passwd
不区分大小写(Case Insensitive)
Now we will search for ISMAIL
in a case insensitive manner. We expect to match both ismail
and ISMAIL
in /etc/passwd
file. We will use -i
option in order to specify case insensitivity.
现在,我们将以不区分大小写的方式搜索ISMAIL
。 我们希望在/etc/passwd
文件中同时匹配ismail
和ISMAIL
。 我们将使用-i
选项以指定不区分大小写。
$ grep -i "ISMAIL" /etc/passwd
不区分大小写和递归(Case Insensitive and Recursive)
In some cases we may need to search case insensitive and recursive manner. We will use -r
option in order to make our case insensitive searchs recursively. In this case we will search for ISMAIL
case insensitive in /etc
directory.
在某些情况下,我们可能需要搜索不区分大小写和递归的方式。 我们将使用-r
选项以递归地进行不区分大小写的搜索。 在这种情况下,我们将在/etc
目录中搜索不区分大小写的ISMAIL
。
$ grep -r -i "ISMAIL" /etc
grep 不区分大小写