Re: problems with grep
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Tue, 14 Nov 2006 19:41:07 -0500
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.
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.
- Follow-Ups:
- Re: problems with grep
- From: ltarc3
- Re: problems with grep
- From: Random832
- Re: problems with grep
- References:
- problems with grep
- From: ltarc3
- problems with grep
- Prev by Date: Re: problems with grep
- 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
|