Jotne
1
My awk
(GNU Awk 3.1.8 on Ubuntu 12.04) seems to ignore case.
cat file
abc
ABC
aBc
123
awk '/[a-z]/&&/[A-Z]/{print $0,"[PASS]";next}{print $0,"[FAIL]"}' file
My result:
abc [PASS]
ABC [PASS]
aBc [PASS]
123 [FAIL]
Correct result:
abc [FAIL]
ABC [FAIL]
aBc [PASS]
123 [FAIL]
Other example
cat d
a
b
C
D
awk '/[A-Z]/' d
b
C
D
1 Like
Interesting. gawk 3.1.5 does the same thing.
Jotne
3
Ahh, good I am not alone with this
Some other strange test
echo a | awk '/[A-Z]/'
<no output>
echo b | awk '/[A-Z]/'
b
echo aa | awk '/[A-Z]/'
<no output>
echo ab | awk '/[A-Z]/'
ab
Single small a
seems to work, but nothing else, strange
This is probably a locale issue. Try:
echo b | awk '/[[:upper:]]/'
Jotne
5
Thanks
[[:upper:]]
[[:lower:]]
seems to work correct.
But so should A-Z
and a-z
do also
It has to do with locales as Scrutinizer mentioned:
Ranges and Locales - The GNU Awk User's Guide
1 Like
Jotne
7
Uff, this tells me that I have to take care when handling upper/lower case issue.
Thanks