[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: delete file based on content

[ format recovered -- Microsoft pseudo-Latin1 ]

Greg Folkert <greg@gregfolkert.net> writes:
> On Mon, 2004-01-05 at 18:35, Michael Martinell wrote:
> > I am trying to delete files based upon content.  As an example I
> > have files called log1, log2, log3
> > 
> > Log 1 contains the words "Processing completed correctly" and can
> > be deleted.
> > 
> > I tried the following: grep -li "Processing completed correctly" *
> >
> > This gave me the list of logs that were complete.  How can I send
> > the results of this to the rm command.  The redirection that I
> > tried did not seem to work.
> rm -f $(grep -li "Processing completed correctly" * | \
> cut -f1 -d: | sort | uniq )

I'm confused.  "grep -l" already gives you only the filenames that
match, so why are you cutting at ":"?  Also, why go through the
"sort|uniq" pipe?  Do the files need to be deleted in a certain order?

ITYM the following:

  $ grep -li "Processing completed correctly" * | xargs rm -f

Beware that this will do unexpected things if filenames have
whitespace in them (as will the command given by Greg).

Hope this helps,
Lucas Bergman <lucas@fivesight.com>
Tired of getting duplicate copies of mailing list messages?  I respect
the 'mail-followup-to' header field: http://cr.yp.to/proto/replyto.html

Reply to: