Chris Devers wrote:
On Fri, 30 Jul 2004, Andrew Gaffney wrote:

I need to get a list of all the files that end with '.html' in a directory and all of its subdirectories. I then want to search through each file and remove the ones from the list that contain '<%perl>' or '<%init>'. How can I do this? Thanks for any help.


 From a Unix command line, you could do something like this:

    $ find /path/to/htdocs -type f | xargs egrep -li '<%(perl|init)>'

The above line results in a list of all the files that have either '<%perl>' or '<%init>' in them.

From here, you can o a step further by deleting them all. Because files with spaces in their name (or their path) can break this horribly, I'll use `sed` to wrap each line in quotes before removing them:

    $ find /path/to/htdocs -type f | \
    > xargs egrep -li '<%(perl|init)>' | \
    > sed 's/\(.*\)/"\1"/' | \
    > xargs rm -i

This should also prompt you before taking any action, in case you realize that you really wanted one of these files. If you want to just proceed blindly -- and my but you're brave if you do -- then delete the "-i" from the last line.

I think you misunderstand. I don't want to delete the files that contain '<%perl>' or '<%init>'. I just want to make a list of all .html files in a directory tree and remove the ones that contains '<%perl>' or '<%init>' from my list.


--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to