need help with script and sed

Bill Moran wmoran at potentialtech.com
Fri Feb 18 18:06:00 GMT 2005


Frank Laszlo <laszlof at tvog.net> wrote:
> Jim Pazarena wrote:
> 
> > I would like to traverse my /users/home tree searching
> > for all regular files and change any lines which read:
> >   "/cgi-bin/Count.cgi ..." to:
> >   "http://counter.qcislands.net/cgi-bin/Count.cgi ..."
> >
> > I kinda think that a 'find' with an -exec of 'sed' would do
> > it but I'm not sure, and even if it were, I'm not sure of
> > the syntax.
> >
> > Could someone help me please?
> >
> > Thanks!
> > Jim
> >
> 
> for i in `find /users/home -type f`; do
>     sed -i '' 
> "s|/cgi-bin/Count.cgi|http://counter.qcislands.net/cgi-bin/Count.cgi|g" $i
> done

The only thing I would recommend different is to provide a backup file
extension to the -i option of sed.  That way it keeps a copy of the file
as it was before sed touches it.  This will save you a lot of headaches,
if sed does something you don't expect.

-- 
Bill Moran
Potential Technologies
http://www.potentialtech.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20050218/7efc9d75/attachment.bin


More information about the freebsd-questions mailing list