[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-user
Subject:    Re: [gentoo-user] Re: OT: global search and replace
From:       Andrew Ross <aross () westnet ! com ! au>
Date:       2004-09-09 11:48:29
Message-ID: 1094730509.4105.4.camel () localhost
[Download RAW message or body]

On Thu, 2004-09-09 at 14:18, Alexander Skwar wrote:
> Andrew Ross wrote:
> 
> > # Do the substitution on all files in current dir and subdirs
> > ( find . ) | while read FILE
> > do
> > 	sed -i 's/oldhostname/newhostname/g' "${FILE}"
> > done
> 
> This not only finds files, but also directories. Because of this,
> "-type f" should be passed to find:

sed is smart enough that you can feed it directories without problem. Of
course, the addition of "-type f" does make the solution feel cleaner
:-)

> find . -type f | while read FILE
> 
> What do the ( ) do?

Causes find to run in a subshell. I wasn't sure if this was strictly
neccessary, but IIRC there are/were bash bugs relating to pipes and
read, which were solved by using the subshells. I could be wrong
though...

Either way, Korthrun's use of -exec removes the need for while, read,
etc and is the superior solution IMHO.

Cheers

Andrew


--
gentoo-user@gentoo.org mailing list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic