It is currently Sat, 09 Dec 2023 06:06:12 GMT

Author Message
 csh/grep problem (on Linux)

[ Article reposted from comp.os.linux.misc,comp.unix.questions ]
[ Author was Roy Gordon <> ]
[ Posted on Mon, 03 Jan 2000 06:30:57 GMT ]

[ Whoops, this also looks like an appropriate group! -- roy ]

My other ISP runs Linux and there seems to be the following grep/egrep
problem when I run csh.  The problem does not arise with bash or ksh.

Here's the problem:

        When '^' is the first character in the grep/egrep search pattern
        and '*' appears in the filname position, grep/egrep treat '^'
        as a literal and not as a metacharacter.

I have two files, junk and junk1.  They differ only in that '^' is
the first character in junk1.

        67 > cat junk
        68 > cat junk1

        77 > egrep 'sql' j*  ; show that filename expansion is working
        78 >

Now, look at the following:

        71 > egrep '^sql' j*
        72 >

This isn't correct!!  '^' as the first character in a grep/egrep
search pattern is a metacharacter standing for the beginning of a
line.  But it's being interpreted literally here.  So it matches.

Notice that if I use junk1 instead of j* that it gets it right.

        72 > egrep '^sql' junk1
        73 >

That is, the pattern isn't found because the requesting pattern is
'sql' at the beginning of a line.  (The first line in junk1 is '^sql',
where '^' is simply another character in the file, so it doesn't match
with 'sql' at the beginning of the line.)

Similarly, things work properly if I put in both file names explicitly:

        80 > egrep '^sql' junk junk1
        81 >

If I run bash (or ksh) instead of csh, they get it right.  For example,
in bash:

        73 > bash
        bash$ egrep '^sql' j*

Again, csh gets it wrong, but only when a * is in the filename:

I don't have this problem on the various Solaris and SunOS 4.X systems
I have access to, just on this Linux system.

For what it's worth, here's what 'uname -a' on the Linux system shows:

        Linux bolt 2.0.36 #1 Tue Nov 24 05:29:56 PST 1998 i686

-- Roy

 Fri, 21 Jun 2002 03:00:00 GMT   
   [ 1 post ] 

Similar Threads

1. csh/grep problem (on Linux)

2. grep and csh

3. Recursive grep alias in csh

4. grep-ing a string in csh

5. csh/tchs: odd behaviour on prog | grep -q string

6. tail | grep | grep | grep

7. grep sTerm * | grep -v grep ???

8. Linux and XPG4 - grep problem

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software