Re: problems with grep
- From: Random832 <random@xxxxxxxxxxxxx>
- Date: 15 Nov 2006 02:07:08 GMT
2006-11-15 <3a4q24-kmi.ln1@xxxxxxxxxxxxxxxxxx>,
Chris F.A. Johnson wrote:
On 2006-11-15, ltarc3@xxxxxxxxx wrote:
I'm having a weird problem with grep. The context isn't that
important, but I will give it to you anyway.
I want to write a script that will look at other scripts and find
variables that are all caps, underscores, and digits. I had a fairly
complicated command with seds and awks and greps that was giving me
problems. I worked my way back to the simplest of greps where I am
just trying to match one uppercase character and now I am absolutely
stymied.
I've run this on FC3, CentOS 4.3.
Am I missing something obvious?? Here is an example:
[root@myhost tmp]# cat testfile
ABC=
abc=
XYZ=
xyz=
123
ABC_123
abc_123
XYZ_123
xyz_123
[root@myhost tmp]# grep "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" testfile
ABC=
XYZ=
ABC_123
XYZ_123
[root@myhost tmp]# grep "[A-Z]" testfile
ABC=
abc=
XYZ=
xyz=
ABC_123
abc_123
XYZ_123
xyz_123
Why is this matching lower-case strings?
Presumably because your locale folds interleaves and lower case to
emulate case insensitivity.
[root@myhost tmp]# grep "^[A-Z_0-9]" testfile
ABC=
XYZ=
xyz=
123
ABC_123
XYZ_123
xyz_123
And why does this match xyz but not abc ????
Your collation sequence is probably aAbBcCdDeE....xXyYzZ, so [A-Z]
does not include "a".
It's just so weird.
I always use LC_ALL=C.
You're supposed to use [[:upper:]] - like "^[[:upper:][:digit:]_]"
.
- References:
- problems with grep
- From: ltarc3
- Re: problems with grep
- From: Chris F.A. Johnson
- problems with grep
- Prev by Date: Re: How to get closing times of applications using shell
- Next by Date: Re: How to get closing times of applications using shell
- Previous by thread: Re: problems with grep
- Next by thread: Re: problems with grep
- Index(es):
Relevant Pages
|