[H-GEN] filter script

Craig Eldershaw ce at comlab.ox.ac.uk
Fri Jan 12 05:40:55 EST 2001


[ Humbug *General* list - semi-serious discussions about Humbug and  ]
[ Unix-related topics.  Please observe the list's charter.           ]
[ Worthwhile understanding: http://www.humbug.org.au/netiquette.html ]

>However scripting is alien to me, I can get grep to identify the files I
>want removed (grep -l From: idiot at somewhere *) but I cant get rm or mv 
>or whatever to then delete or otherwise deal with the dross.
>
>I thought that perhaps the grep output piped to mv or rm may work but I 
>can't get it to go.

Piping things only (in general) works if the program you are piping TO
expects input to come from the standard input (eg. typed in by you).

>Can someone give me a broad push

As with most things in unix, there's many ways of doing this.

>From most shell prompts:

   rm `grep -l From: idiot at somewhere *`

(note the direction of the quotes)

or in Bourne shells specifically:

   for i in `grep -l From: idiot at somewhere *`
   do
      echo Deleting silly post $i
      rm $i
   done

or 

   grep -l From: idiot at somewhere * | xargs rm

are all possibilities.

Alternatively, count slowly to 10 and some Humbugger will post the Perl
solution (wait for another slow count of 10 and the battle as to the
"best" way to do it in Perl will have been joined :-).

HTH,

C.


--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.



More information about the General mailing list