grep 区分大小写 [A-Z]? [英] grep case sensitive [A-Z]?

查看:26
本文介绍了grep 区分大小写 [A-Z]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用此模式让 grep 进行区分大小写的搜索

I cannot get grep to case sensitive search with this pattern

$ grep 'T[A-Z]' test.txt
The Quick Brown Fox Jumps Over The Lazy Dog
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG

推荐答案

使用引号来防止模式被 shell 作为全局匹配到文件系统中的文件.''

Use quotes to prevent the pattern from being matched as a glob to file(s) in the filesystem by the shell. ''

使用命名字符类来保证区分大小写的匹配.[[:lower:]]

Use a named character class to guarantee a case-sensitive match. [[:lower:]]

使用量词匹配多个字符.+

Use a quantifier to make matches for more than one character. +

使用锚点来确保匹配位置正确.^

Use anchor(s) to make sure the match is positioned properly. ^

grep '^T[[:upper:]]+' test.txt

[A-Z] 不适合您的原因是您使用的语言环境在您的系统上实现的方式,该模式还包括小写字母.

The reason that [A-Z] isn't working for you is that the way the locale you're using is implemented on your system, that pattern also includes lowercase letters.

这篇关于grep 区分大小写 [A-Z]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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