bash 如何grep文件中不区分大小写的字符串?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48492422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:37:46  来源:igfitidea点击:

How to grep for case insensitive string in a file?

bashshellawksedgrep

提问by all_techie

I have a file file1which ends with Success...OR success...

我有一个file1Success...OR 结尾 的文件success...

I want to grepfor the word successin a way which is not case sensitive way.

我想以一种不区分大小写的方式来grep表示这个词success

I have written the following command but it is case sensitive

我已经编写了以下命令,但它区分大小写

cat file1 | grep "success\.\.\."

cat file1 | grep "success\.\.\."

How can i change it so that it returns 0with both Success...OR success...

我怎样才能改变它,以便它returns 0与两个Success...success...

回答by Imran

You can use the -iflag which makes your pattern case insensitive:

您可以使用-i使您的模式不区分大小写的标志:

grep -iF "success..." file1

Also, there is no need for cat. greptakes a file with the syntax grep <pattern> <file>. I also used the -Fflag to search for a fixed string to avoid escaping the ellipsis.

此外,也不需要cat. grep使用语法为grep <pattern> <file>. 我还使用该-F标志来搜索固定字符串以避免转义省略号。

回答by Daljit Sinz

For me SQL=echo $line | grep -iF "SQL"; IT works perfect

对我来说 SQL= echo $line | grep -iF "SQL"; IT 工作完美