On Mon, 2004-01-12 at 21:32, Phillip Hellewell wrote:
> > You can do that with sed:
> > 
> > grep -lr "stringToReplace" | xargs sed -i -e "s/stringToReplace//g"
> 
> Don't you need a * after the "stringToReplace"?  Also, my sed doesn't
> have -i option.  Finally, my sed is sending the output to stdout instead
> of replacing the file.
> 
> So, what am I missing here?  I was just curious because this seems quite
> useful to me.

Sorry, there should be a * there:

grep -lr "stringToReplace" * | xargs sed -i -e "s/stringToReplace//g"

Here's a summary of the options:
grep:
 -l filename only
 -r recurse into directories

xargs then turns each of the filenames returned from grep into an
argument for sed.  The options for sed are:
 -i do the replacement to the file in place.  If you specify an argument
after -i (e.g., -i .bak) the file will be backed up to oldFileName.bak. 
Otherwise it will just change the file, instead of putting it out to
stdout.  I'm running debian/sid.  I don't know if that version of sed is
different than others.
  -e I think this is optional.  It just means that the sed commands will
follow.
  
I don't know if there is a more efficient way to do this, but I've found
it quite useful several times.

Casey

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
newbies mailing list
[EMAIL PROTECTED]
http://phantom.byu.edu/cgi-bin/mailman/listinfo/newbies

Reply via email to