simple grep & find script doesn't work under AIX 3.2

simple grep & find script doesn't work under AIX 3.2

Post by Daniel Wrigh » Tue, 24 Dec 1996 04:00:00



Okay, I spent way too long writing this simplistic script and debugging
it, and suddenly, I try it out on another machine and I get complaints
about grep usage AND that bin is not executable (I'm not trying to
execute it, it's a directory and has execute permissions, so I can read
the directory!).
The difference is that I wrote it on an AIX 4.1 machine, and it fails
miserably under AIX 3.2.
Both the "-v" and "-l" options for grep are supported by the earlier
AIX.
The shell used is Korn.

The whole idea is to do a fast search of all source code, without
hardcoding specific source subdirectories and avoiding searching things
which are obviously not source code.  (On the machine I wrote the script
on, this cut the search to about 2.5 minutes, down from 10-15 minutes,
for a simple find, followed by grep).

The script:
PATTERN=${1}
ls ${SRCDIR} | grep -v ^bin | grep -v ^rpt | grep -v ^tmp | \

grep -v "\.o$" | grep -v "\.4ge$" | \
xargs grep -l ${PATTERN}

basically it gets a list of everythings in the source directory,
excluding ones where source code will never be present,
finds all the files in those directories,
 excluding object and binary files
amd greps for the pattern, returning a list of all files referencing
the pattern.
I have abbreviated the list of directories and file types excluded, but
not by very much.  Also, note, that if I didn't cut and paste the above
code, so bear in mind that it does work under AIX 4.1.

Please, any suggestions will be listened to with great interest, and if
 I can fix it, I will post the fix, however, I am reasonably confident
 that this should work under just about any unix!

This would not be the first time, AIX has been very bad to me;
does anyone know why IBM still has the market presence outside of the
mainframe world???

Incidentally AIX 4.1 contains a particularly * bug that set
the record for number of pager calls in a week at my company, so please
don't tell me the answer is to upgrade (it's our customer's decision
anyway, and I'd sooner they'd invest their upgrade dollars into
frame relay as modems just don't cut it in the business world today!)

Thanx in advance,

#include <StdDisclaimers.h>

 
 
 

simple grep & find script doesn't work under AIX 3.2

Post by Bill Marc » Wed, 25 Dec 1996 04:00:00



>Okay, I spent way too long writing this simplistic script and debugging
>it, and suddenly, I try it out on another machine and I get complaints
>about grep usage AND that bin is not executable (I'm not trying to
>execute it, it's a directory and has execute permissions, so I can read
>the directory!).
>The difference is that I wrote it on an AIX 4.1 machine, and it fails
>miserably under AIX 3.2.
>Both the "-v" and "-l" options for grep are supported by the earlier
>AIX.
>The shell used is Korn.

In some versions of Bourne shell, the ^ character is a synonym for | .  I
don't know whether some Korn shells do this, or perhaps your script is
running in sh (Did you use #!/bin/ksh in the first line?  If so, are you
sure ksh is in the /bin directory?)  Anyway, try single quotes or
backslashes wherever you have a ^ in your script.

>The script:
>PATTERN=${1}
>ls ${SRCDIR} | grep -v ^bin | grep -v ^rpt | grep -v ^tmp | \

>grep -v "\.o$" | grep -v "\.4ge$" | \
>xargs grep -l ${PATTERN}

--


 
 
 

simple grep & find script doesn't work under AIX 3.2

Post by Larry Star » Thu, 26 Dec 1996 04:00:00



> Okay, I spent way too long writing this simplistic script and debugging
> it, and suddenly, I try it out on another machine and I get complaints
> about grep usage AND that bin is not executable (I'm not trying to
> execute it, it's a directory and has execute permissions, so I can read
> the directory!).
> The difference is that I wrote it on an AIX 4.1 machine, and it fails
> miserably under AIX 3.2.
> Both the "-v" and "-l" options for grep are supported by the earlier
> AIX.
> The shell used is Korn.

> The whole idea is to do a fast search of all source code, without
> hardcoding specific source subdirectories and avoiding searching things
> which are obviously not source code.  (On the machine I wrote the script
> on, this cut the search to about 2.5 minutes, down from 10-15 minutes,
> for a simple find, followed by grep).

> The script:
> PATTERN=${1}
> ls ${SRCDIR} | grep -v ^bin | grep -v ^rpt | grep -v ^tmp | \

> grep -v "\.o$" | grep -v "\.4ge$" | \
> xargs grep -l ${PATTERN}

> basically it gets a list of everythings in the source directory,
> excluding ones where source code will never be present,
> finds all the files in those directories,
>  excluding object and binary files
> amd greps for the pattern, returning a list of all files referencing
> the pattern.
> I have abbreviated the list of directories and file types excluded, but
> not by very much.  Also, note, that if I didn't cut and paste the above
> code, so bear in mind that it does work under AIX 4.1.

> Please, any suggestions will be listened to with great interest, and if
>  I can fix it, I will post the fix, however, I am reasonably confident
>  that this should work under just about any unix!

> This would not be the first time, AIX has been very bad to me;
> does anyone know why IBM still has the market presence outside of the
> mainframe world???

> Incidentally AIX 4.1 contains a particularly * bug that set
> the record for number of pager calls in a week at my company, so please
> don't tell me the answer is to upgrade (it's our customer's decision
> anyway, and I'd sooner they'd invest their upgrade dollars into
> frame relay as modems just don't cut it in the business world today!)

> Thanx in advance,

> #include <StdDisclaimers.h>

The following, note the use the shell header on your script to insure
that
it is executed by the intended shell, should do the job for you.

#!/usr/bin/ksh
PATTERN=$1
find ${SRC} -type f \( ! -name '*.o' ! -name '*.4ge' \) \
   -exec grep -l ${PATTERN} {} \; \
   -o -type d \( -name bin -o -name rpt -o -name tmp \) -prune

Should do the job nicely invoking the "grep" command only once.
--

================================================================
There are only three sports: bullfighting, motor racing, and
mountaineering; all the restare merely games. - Ernest Hemingway

 
 
 

simple grep & find script doesn't work under AIX 3.2

Post by Brian Duan » Fri, 27 Dec 1996 04:00:00




> > Okay, I spent way too long writing this simplistic script and debugging
> > it, and suddenly, I try it out on another machine and I get complaints
> > about grep usage AND that bin is not executable (I'm not trying to
> > execute it, it's a directory and has execute permissions, so I can read
> > the directory!).
> > The difference is that I wrote it on an AIX 4.1 machine, and it fails
> > miserably under AIX 3.2.
> > Both the "-v" and "-l" options for grep are supported by the earlier
> > AIX.
> > The shell used is Korn.

> > The whole idea is to do a fast search of all source code, without
> > hardcoding specific source subdirectories and avoiding searching things
> > which are obviously not source code.  (On the machine I wrote the script
> > on, this cut the search to about 2.5 minutes, down from 10-15 minutes,
> > for a simple find, followed by grep).

> > The script:
> > PATTERN=${1}
> > ls ${SRCDIR} | grep -v ^bin | grep -v ^rpt | grep -v ^tmp | \

> > grep -v "\.o$" | grep -v "\.4ge$" | \
> > xargs grep -l ${PATTERN}

> > basically it gets a list of everythings in the source directory,
> > excluding ones where source code will never be present,
> > finds all the files in those directories,
> >  excluding object and binary files
> > amd greps for the pattern, returning a list of all files referencing
> > the pattern.
> > I have abbreviated the list of directories and file types excluded, but
> > not by very much.  Also, note, that if I didn't cut and paste the above
> > code, so bear in mind that it does work under AIX 4.1.

> > Please, any suggestions will be listened to with great interest, and if
> >  I can fix it, I will post the fix, however, I am reasonably confident
> >  that this should work under just about any unix!

> > This would not be the first time, AIX has been very bad to me;
> > does anyone know why IBM still has the market presence outside of the
> > mainframe world???

> > Incidentally AIX 4.1 contains a particularly * bug that set
> > the record for number of pager calls in a week at my company, so please
> > don't tell me the answer is to upgrade (it's our customer's decision
> > anyway, and I'd sooner they'd invest their upgrade dollars into
> > frame relay as modems just don't cut it in the business world today!)

> > Thanx in advance,

> > #include <StdDisclaimers.h>

> The following, note the use the shell header on your script to insure
> that
> it is executed by the intended shell, should do the job for you.

> #!/usr/bin/ksh
> PATTERN=$1
> find ${SRC} -type f \( ! -name '*.o' ! -name '*.4ge' \) \
>    -exec grep -l ${PATTERN} {} \; \
>    -o -type d \( -name bin -o -name rpt -o -name tmp \) -prune

> Should do the job nicely invoking the "grep" command only once.

That's not correct!  The 'exec' will cause the 'grep' to be invoked for
each filename that gets past the preceding qualifiers.

> --

> ================================================================
> There are only three sports: bullfighting, motor racing, and
> mountaineering; all the restare merely games. - Ernest Hemingway

--

 
 
 

simple grep & find script doesn't work under AIX 3.2

Post by Larry Star » Sat, 28 Dec 1996 04:00:00





> > > Okay, I spent way too long writing this simplistic script and debugging
> > > it, and suddenly, I try it out on another machine and I get complaints
> > > about grep usage AND that bin is not executable (I'm not trying to
> > > execute it, it's a directory and has execute permissions, so I can read
> > > the directory!).
> > > The difference is that I wrote it on an AIX 4.1 machine, and it fails
> > > miserably under AIX 3.2.
> > > Both the "-v" and "-l" options for grep are supported by the earlier
> > > AIX.
> > > The shell used is Korn.

> > > The whole idea is to do a fast search of all source code, without
> > > hardcoding specific source subdirectories and avoiding searching things
> > > which are obviously not source code.  (On the machine I wrote the script
> > > on, this cut the search to about 2.5 minutes, down from 10-15 minutes,
> > > for a simple find, followed by grep).

> > > The script:
> > > PATTERN=${1}
> > > ls ${SRCDIR} | grep -v ^bin | grep -v ^rpt | grep -v ^tmp | \

> > > grep -v "\.o$" | grep -v "\.4ge$" | \
> > > xargs grep -l ${PATTERN}

> > > basically it gets a list of everythings in the source directory,
> > > excluding ones where source code will never be present,
> > > finds all the files in those directories,
> > >  excluding object and binary files
> > > amd greps for the pattern, returning a list of all files referencing
> > > the pattern.
> > > I have abbreviated the list of directories and file types excluded, but
> > > not by very much.  Also, note, that if I didn't cut and paste the above
> > > code, so bear in mind that it does work under AIX 4.1.

> > > Please, any suggestions will be listened to with great interest, and if
> > >  I can fix it, I will post the fix, however, I am reasonably confident
> > >  that this should work under just about any unix!

> > > This would not be the first time, AIX has been very bad to me;
> > > does anyone know why IBM still has the market presence outside of the
> > > mainframe world???

> > > Incidentally AIX 4.1 contains a particularly * bug that set
> > > the record for number of pager calls in a week at my company, so please
> > > don't tell me the answer is to upgrade (it's our customer's decision
> > > anyway, and I'd sooner they'd invest their upgrade dollars into
> > > frame relay as modems just don't cut it in the business world today!)

> > > Thanx in advance,

> > > #include <StdDisclaimers.h>

> > The following, note the use the shell header on your script to insure
> > that
> > it is executed by the intended shell, should do the job for you.

> > #!/usr/bin/ksh
> > PATTERN=$1
> > find ${SRC} -type f \( ! -name '*.o' ! -name '*.4ge' \) \
> >    -exec grep -l ${PATTERN} {} \; \
> >    -o -type d \( -name bin -o -name rpt -o -name tmp \) -prune

> > Should do the job nicely invoking the "grep" command only once.

> That's not correct!  The 'exec' will cause the 'grep' to be invoked for
> each filename that gets past the preceding qualifiers.

> --


As Brian correctly pointed out the "grep" is invoked for each file being
searched.
I guess I am guilty of stating what I meant poorly, the above command
eliminates
the pipelines of "grep -v" used to prune the file tree, and filenames,
being searched.

Sorry if I confused anyone!

--

================================================================
There are only three sports: bullfighting, motor racing, and
mountaineering; all the restare merely games. - Ernest Hemingway

 
 
 

simple grep & find script doesn't work under AIX 3.2

Post by Mark D. Stoc » Tue, 31 Dec 1996 04:00:00



>  > Okay, I spent way too long writing this simplistic script and debugging

 > it, and suddenly, I try it out on another machine and I get complaints
 > about grep usage AND that bin is not executable (I'm not trying to
 > execute it, it's a directory and has execute permissions, so I can read
 > the directory!).
 > The difference is that I wrote it on an AIX 4.1 machine, and it fails
 > miserably under AIX 3.2.
 > Both the "-v" and "-l" options for grep are supported by the earlier
 > AIX.
 > The shell used is Korn.
Quote:>  > The whole idea is to do a fast search of all source code, without

 > hardcoding specific source subdirectories and avoiding searching things
 > which are obviously not source code.  (On the machine I wrote the script
 > on, this cut the search to about 2.5 minutes, down from 10-15 minutes,
 > for a simple find, followed by grep).
Quote:>  > The script:

 > PATTERN=${1}
 > ls ${SRCDIR} | grep -v ^bin | grep -v ^rpt | grep -v ^tmp | \

 > grep -v "\.o$" | grep -v "\.4ge$" | \
 > xargs grep -l ${PATTERN}
Quote:>  > basically it gets a list of everythings in the source directory,

 > excluding ones where source code will never be present,
 > finds all the files in those directories,
 >  excluding object and binary files
 > amd greps for the pattern, returning a list of all files referencing
 > the pattern.
 > I have abbreviated the list of directories and file types excluded, but
 > not by very much.  Also, note, that if I didn't cut and paste the above
 > code, so bear in mind that it does work under AIX 4.1.
Quote:>  > Please, any suggestions will be listened to with great interest, and if

 >  I can fix it, I will post the fix, however, I am reasonably confident
 >  that this should work under just about any unix!

Have you tried putting args in quotes? Like so:

        PATTERN=${1}
        ls ${SRCDIR} | grep -v "^bin" | grep -v "^rpt" | grep -v "^tmp" | \

        grep -v "\.o$" | grep -v "\.4ge$" | \
        xargs grep -l ${PATTERN}

Hope that helps,
--

Mark.

+-------------------------------------------------------------------------+
|Mark D. Stock - The West Solutions Group           http://www.west.co.za |
|                            The Informix FAQ is at http://www.iiug.org   |

|Tel:   +27 11 803 2151  |If it doesn't work... force it!                 |
|Fax:   +27 11 803 2189  |If it breaks... it needed replacing anyway!     |
|Cell:  +27 83 250 2325  |Well, that's how I code anyway!                 |
+------------------------+------------------------------------------------+