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
The default behavior of the grep command is case sensitive. Case sensitive accepts the lower case different from uppercase. For example, the pattern “LINUX” doesn’t matches with the “linux” or “Linux” or “LinuX” etc. The text file is like below. We will use the following grep command which is case sensitive by default. The output is like below.
The –ignore-case is the long-form version of the -i option. So we can use the –ignore-case for case insensitive match with the grep command too. Alternatively, another command output can be also grepped with the grep command. This command output can be grepped in a case insensitive manner by using the -i option.
The simplest feature of grep is to handle case sensitivity. Grep is case-sensitive by default hence it shows the perceptibility of both upper and lower cases in the file.
The simplest feature of grep is to handle case sensitivity. Grep is case-sensitive by default hence it shows the perceptibility of both upper and lower cases in the file. This feature helps in getting the required output by removing the discrimination of the case which can all be done on the main page of grep.
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.
You can set LANG value:
$ LANG=C grep 'T[A-Z]' test.txt
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With