Re: problems with grep



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:]_]"
.



Relevant Pages

  • Re: problems with grep
    ... I want to write a script that will look at other scripts and find ... And why does this match xyz but not abc ???? ...
    (comp.unix.shell)
  • Re: script to take backup
    ... >> i want to create a script to take backup of specific directories. ... >> how can i list only abc, xyz and bcd directories in the search. ...
    (comp.unix.aix)
  • Expect: spawned process in sleep state (log_file problem?)
    ... I have a working Expect script which spawns another tcl script ... #-- First, spawn the xyz script ... puts "abc is $abc" ... the xyz script ran in background. ...
    (comp.lang.tcl)
  • Re: problems with grep
    ... older systems upper case A-Z came before a. ... And why does this match xyz but not abc ???? ...
    (comp.unix.shell)
  • Re: A subquery? Not sure if this is doable?
    ... the weekly series and the repeating monthly figure. ... 1/12/05 ABC 4.22 ... 1/12/05 DEF 3.12 ... 1/12/05 XYZ 8.88 ...
    (microsoft.public.access.queries)