如何grep在文件中不区分大小写的字符串? [英] How to grep for case insensitive string in a file?

查看:258
本文介绍了如何grep在文件中不区分大小写的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆