Re: delete file based on content
On Mon, Jan 05, 2004 at 07:28:31PM -0500, Paul Morgan wrote: On Mon, 05 Jan 2004 18:18:00 -0600, Michael Martinell wrote: #rm `grep -li Processing completed correctly *` This worked nicely at the command line, however when I put in into a script I received the error rm :too few arguments Any other thoughts? You would get that, at the command line or in a script, if there were no filenames returned by grep (i.e. none to delete). You can check by simply typing rm by itself and you'll get the same error message. To suppress the error message, you could do this: rm `grep -li Processing completed correctly *` 2/dev/null This is ugly, Paul: It'd suppress not only this message, but other messages which would possibly be worth noticing. Given sufficient number of executions, such a message will appear--and we would miss it. -- Jan Minar Please don't CC me, I'm subscribed. x 7 pgp0.pgp Description: PGP signature
Re: delete file based on content
On Tue, Jan 06, 2004 at 08:10:44AM +0100, Jan Minar wrote: On Mon, Jan 05, 2004 at 07:28:31PM -0500, Paul Morgan wrote: [snip] rm `grep -li Processing completed correctly *` 2/dev/null This is ugly, Paul: It'd suppress not only this message, but other messages which would possibly be worth noticing. Given sufficient number of executions, such a message will appear--and we would miss it. How about if [[ `grep -li Processing completed correctly *` != ]]; then rm `grep -li Processing completed correctly *` fi although from what I've read in The Unix Haters Handbook, Paul's way is more in line with the unix philosophy -- laziness. In this case, you should expect rm files you can write to succeed ?? -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: delete file based on content
On Mon, Jan 05, 2004 at 11:26:51PM -0800, Nano Nano wrote: [snip] err on second thought I can see why xargs is better here -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: delete file based on content
On Mon, 2004-01-05 at 18:35, Michael Martinell wrote: Can anybody tell me what I am doing wrong? 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 ) That will get you the proper command. Now run along and read up on bash with man bash It is a good read for those that don't understand it, but want to use its functionality. -- [EMAIL PROTECTED] REMEMBER ED CURRY! http://www.iwethey.org/ed_curry signature.asc Description: This is a digitally signed message part
Re: delete file based on content
[ format recovered -- Microsoft pseudo-Latin1 ] Greg Folkert [EMAIL PROTECTED] 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 -- Lucas Bergman [EMAIL PROTECTED] Tired of getting duplicate copies of mailing list messages? I respect the 'mail-followup-to' header field: http://cr.yp.to/proto/replyto.html -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: delete file based on content
On Tue, 06 Jan 2004 08:10:44 +0100, Jan Minar wrote: On Mon, Jan 05, 2004 at 07:28:31PM -0500, Paul Morgan wrote: On Mon, 05 Jan 2004 18:18:00 -0600, Michael Martinell wrote: #rm `grep -li Processing completed correctly *` This worked nicely at the command line, however when I put in into a script I received the error rm :too few arguments Any other thoughts? You would get that, at the command line or in a script, if there were no filenames returned by grep (i.e. none to delete). You can check by simply typing rm by itself and you'll get the same error message. To suppress the error message, you could do this: rm `grep -li Processing completed correctly *` 2/dev/null This is ugly, Paul: It'd suppress not only this message, but other messages which would possibly be worth noticing. Given sufficient number of executions, such a message will appear--and we would miss it. Jan, Notice I said could, not should. I was of course aware that I am sinking all error messages, but it was meant as an example, as I also pointed the poster at the relevant section of the bash manpages who would then have seen what the redirection did. It was not my intention to write a full script with complete error handling so he didn't have to see the too few arguments message. But thank you for being picky, Jan, even if you didn't offer an alternative (joking), because it made me think. So, seeing as you mentioned it (and replacing the archaic backticks): fgrep -q Processing completed correctly * rm $(fgrep -li Processing completed correctly *) Kind of slow, what with the two passes, though. So, one could get cute: tf=$(tempfile);rm $(fgrep -li Processing completed correctly *) $tf;unset tf or just (tf=$(tempfile);rm $(fgrep -li Processing completed correctly *) $tf) Figuring out the command lists above is left as an exercise for the original poster, the point being that there is more than one way to skin a cat. -- paul Programming without a hex editor is like watchmaking without a hammer. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: delete file based on content
On Mon, Jan 05, 2004 at 11:26:51PM -0800, Nano Nano wrote: On Tue, Jan 06, 2004 at 08:10:44AM +0100, Jan Minar wrote: On Mon, Jan 05, 2004 at 07:28:31PM -0500, Paul Morgan wrote: [snip] rm `grep -li Processing completed correctly *` 2/dev/null This is ugly, Paul: It'd suppress not only this message, but other messages which would possibly be worth noticing. Given sufficient number of executions, such a message will appear--and we would miss it. How about if [[ `grep -li Processing completed correctly *` != ]]; then rm `grep -li Processing completed correctly *` fi although from what I've read in The Unix Haters Handbook, Paul's way is more in line with the unix philosophy -- laziness. You could use rm -f which will ignore empty files (this is how it is usually used in the clean directive in make files. I am not sure how the proposed method will work with files containing spaces btw. In this case, you should expect rm files you can write to succeed ?? -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: delete file based on content
On Mon, Jan 05, 2004 at 05:35:26PM -0600, Michael Martinell wrote: [snip] 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 `grep -li Processing completed correctly *` -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
RE: delete file based on content
-Original Message- From: Tom [mailto:[EMAIL PROTECTED] Sent: Monday, January 05, 2004 5:41 PM To: [EMAIL PROTECTED] Subject: Re: delete file based on content On Mon, Jan 05, 2004 at 05:35:26PM -0600, Michael Martinell wrote: [snip] 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 `grep -li Processing completed correctly *` This worked nicely at the command line, however when I put in into a script I received the error rm :too few arguments Any other thoughts? -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
RE: delete file based on content
Please ignore former post. It was an ID10T error on my part. -Original Message- From: Tom [mailto:[EMAIL PROTECTED] Sent: Monday, January 05, 2004 5:41 PM To: [EMAIL PROTECTED] Subject: Re: delete file based on content On Mon, Jan 05, 2004 at 05:35:26PM -0600, Michael Martinell wrote: [snip] 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 `grep -li Processing completed correctly *` This worked nicely at the command line, however when I put in into a script I received the error rm :too few arguments Any other thoughts? -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: delete file based on content
(oops, list reply) On Mon, Jan 05, 2004 at 06:08:02PM -0600, Michael Martinell wrote: #rm `grep -li Processing completed correctly *` Any other thoughts? grep -Zli Processing completed correctly * | xargs -r0 rm -v -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
RE: delete file based on content
On Mon, 05 Jan 2004 18:18:00 -0600, Michael Martinell wrote: Please ignore former post. It was an ID10T error on my part. -Original Message- From: Tom [mailto:[EMAIL PROTECTED] Sent: Monday, January 05, 2004 5:41 PM To: [EMAIL PROTECTED] Subject: Re: delete file based on content On Mon, Jan 05, 2004 at 05:35:26PM -0600, Michael Martinell wrote: [snip] 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 `grep -li Processing completed correctly *` This worked nicely at the command line, however when I put in into a script I received the error rm :too few arguments Any other thoughts? You would get that, at the command line or in a script, if there were no filenames returned by grep (i.e. none to delete). You can check by simply typing rm by itself and you'll get the same error message. To suppress the error message, you could do this: rm `grep -li Processing completed correctly *` 2/dev/null man bash /^REDIRECTION ...for information on what I added. -- paul Programming without a hex editor is like watchmaking without a hammer. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]