HP3000-L Archives

November 1998, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
John Korb <[log in to unmask]>
Reply To:
John Korb <[log in to unmask]>
Date:
Fri, 20 Nov 1998 14:01:43 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (102 lines)
At 11/20/98 12:38 PM , Andreas Schmidt wrote:
>John,
>
>a real Unix expert gave me the hint to use the find command.
>
>You may try this:
>
>find ./ -type f -exec grep b {} \; -exec echo file {} \;
>to find s.th. in all the files' content, (but very CPU intensive)
>
>or
>
>find /APACHE/ -type f |grep SCHMI
>to find s.th. in the files' names.
>
>Hope this helps, best regards, Andreas

Thanks Andreas!

Here is what I ended up doing:

   find /COMM/DOC/html -type f | xargs -n1 -i grep -il " database " {}

What I wanted (and received) was a list of the files which contain the
string " database " (notice the blanks before and after), and that is what
the above command generates.

Note that in my case I specified "-il" for grep so that it would be case
insensitive (-i) and only list the name of the files containing the search
word (-l).

As Mark Bixby and Andreas Schmidt both noted (and very kindly), my mistake
was trying to use the "ls" command instead of "find".

The "-type f" option on the "find" command causes "find" to only list files
(as opposed to listing files and directories).

The "xargs" command takes the output of the find command and creates
individual commands from it ("grep" commands in this case).  There are
really three parameter groups to the "xargs" command.  First, the "-n1"
tells "xargs" to use only one file name at a time.  Second, the "-i" tells
"xargs" to replace any instance of "{}" with the file name.  Third, the
"grep -il ' database ' {}" provides the pattern (or template) of the
command(s) that "xargs" is to create from the list the "find" command
generates.

Thanks again to all who wrote!  Once again, the HP3000-L comes through!

John



>[log in to unmask] on 11/20/98 02:45:47 PM
>
>Please respond to [log in to unmask]
>
>To:   [log in to unmask]
>cc:    (bcc: Andreas Schmidt/HI/CSC)
>Subject:  A POSIX question
>
>
>
>
>Another dumb question from a POSIX dummy (me).
>I'm trying to do a "grep" on all files in a particular directory and all
>its subdirectories and I'm running into some problems.  Perhaps one of the
>POSIX gurus knows a solution.  Here is what I have tried (and what I've
>learned):
>o  Since "grep" only allows a file or directory (but no recursive
>   directories), I figured I'd use "ls" to generate a list of files in
>   the directory and its subdirectories, then use "xargs" to turn the
>   file names into targets for "grep".
>o  I know that in the CI I can use:
>      listfile /COMM/DOC/html/,6
>   to get a list of all files in the directory and all files in its
>   subdirectories, but this is an MPE solution and I'm trying to use
>   POSIX.
>o  I know that "ls -Rx1 /COMM/DOC/html" will generate a list of files
>   in the directory and its subdirectories, but it doesn't produce a
>   list of "fully-qualified" file names.  Instead, it lists the directory
>   name and then lists the files in that directory, then a blank line,
>   then the next directory name, then the list of files in that directory,
>   etc.  This is not suitable for "xargs" and "grep".
>Okay, what am I overlooking?  How can I get "ls" to give me the kind of
>file listing that the "listfile,6" command (above) gives me (or is there a
>different command I should be using)?
>Thanks!
>John
>--------------------------------------------------------------
>John Korb                            email: [log in to unmask]
>Innovative Software Solutions, Inc.
>The thoughts, comments, and opinions expressed herein are mine
>and do not reflect those of my employer(s), or anyone else.
>

--------------------------------------------------------------
John Korb                            email: [log in to unmask]
Innovative Software Solutions, Inc.

The thoughts, comments, and opinions expressed herein are mine
and do not reflect those of my employer(s), or anyone else.

ATOM RSS1 RSS2