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

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

问题描述

我有一个文件 file1成功...成功...

I have a file file1 which ends with Success... OR success...

我想以不区分大小写的方式对 success 这个词 grep 进行grep.

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 "成功..."

我如何更改它以便 returns 0Success...成功...

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

推荐答案

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

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

grep -iF "success..." file1

另外,也不需要cat.grep 使用语法 grep 获取文件<文件>.我还使用了 -F 标志来搜索固定字符串以避免转义省略号.

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天全站免登陆