On 05:36 21 Mar 2002, David Kramer <[EMAIL PROTECTED]> wrote:
| On Thu, 21 Mar 2002, Nick Wilson wrote:
| > could someone please help me solve the following problem?
| > I need to recursively find and replace a string in a whole bunch of dirs
| > (a website). For example: 
| > 
| > change: http://my-testing-environment.com
| > to:     http://www.the-real-website.com
| > 
| > I gues sed is the tool for this right?

Yes. Ignore the "perl is my only hammer" types.

| > I've read the man page but I'm
| > somewhat intimidated by it :-)
| 
| Well, you can use sed, but using perl gives one big advantage; it lets you 
| edit files in-place.

Yeah. Sort of. But actually a red herring.

Dude, fetch bsed:

        http://www.zip.com.au/~cs/scripts/bsed

and go:

        find dir -type f -print | xargs bsed 'sed-command'here'

| Actually, it's making a copy first and then 
| overwriting the original, but you don't have to deal with that anyway.  

Actually, no. This is the core reason I stay the hell away from perl's
-i mode: it makes a fresh file with the modified output, then UNLINKS
THE ORIGINAL AND MOVES THE NEW ONE IN ON TOP!

The reasoning behind this is safety from "disc full" and avoiding the
race if having an inconsistent file during the rewrite period). But the
downside is that: it breaks any hard links you might have to the file and
also it mangles the file ownerships and permissions, because what you end
up with is a NEW file with default (umask) permissions and default owner
(you).

Bsed doesn't do that. It makes a new, modified, copy and if that was
ok, writes the copy back over the original. Preserving the file modes
and links.

Perl is overkill and cumbersome for a lot of simple edits that any sane
person would normally use sed for. And thus bsed.

Fetch, use, enjoy. Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

There are old climbers, and there are bold climbers; but there are no old
bold climbers.



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to