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
How to grep for case insensitive string in a file?
提问by all_techie
I have a file file1
which ends with
Success...
OR
success...
我有一个file1
以Success...
OR
结尾
的文件success...
I want to grep
for the word success
in 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 0
with both Success...
OR
success...
我怎样才能改变它,以便它returns 0
与两个Success...
或
success...
回答by Imran
You can use the -i
flag which makes your pattern case insensitive:
您可以使用-i
使您的模式不区分大小写的标志:
grep -iF "success..." file1
Also, there is no need for cat
. grep
takes a file with the syntax grep <pattern> <file>
. I also used the -F
flag 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 工作完美