如何grep在文件中不区分大小写的字符串? [英] How to grep for case insensitive string in a file?
问题描述
我有一个文件 file1
,它以
成功...
或
结尾成功...
我希望 grep
单词 success
以一种不区分大小写的方式。
我写了下面的命令,但它是区分大小写
cat file1 | grepsuccess \.\.\。
我如何更改它以使它返回0
与成功...
或
成功...
您可以使用 -i
标志,这会使您的模式不区分大小写:
grep -iFsuccess ...file1
另外,不需要 cat
。 grep
使用语法 grep< pattern> <文件>
。我还使用 -F
标志搜索固定字符串以避免省略省略号。
I have a file file1
which ends with
Success...
OR
success...
I want to grep
for the word success
in a way which is not case sensitive way.
I have written the following command but it is case sensitive
cat file1 | grep "success\.\.\."
How can i change it so that it returns 0
with both Success...
OR
success...
You can use the -i
flag which makes your pattern case insensitive:
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.
这篇关于如何grep在文件中不区分大小写的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!