grep的区分大小写[A-Z]? [英] grep case sensitive [A-Z]?
问题描述
我不能让的grep
为区分大小写此模式搜索
$的grep'T [A-Z]的test.txt
敏捷的棕色狐狸跳过了懒狗
敏捷的棕色狐狸跳过了懒狗
使用引号prevent被匹配在由外壳文件系统中的水珠到文件(S)模式。
使用指定的字符类,以保证区分大小写的匹配。 [:降低:]]
使用量词,使比赛为多个字符。 \\ +
使用锚(S),以确保比赛的正确定位。 ^
的grep'^ T [:上:]] \\ +'的test.txt
之所以 [AZ]
工作不适合你的是,你正在使用的语言环境是您的系统上实现的方式,该模式还包括小写字母
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
Use quotes to prevent the pattern from being matched as a glob to file(s) in the filesystem by the shell. ''
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
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屋!