[ale] Perl or Python for editing files...

Michael Trausch mike at trausch.us
Tue Oct 18 13:05:05 EDT 2011


On 10/17/2011 03:07 PM, Chuck Payne wrote:
> On Mon, Oct 17, 2011 at 2:59 PM, Pete Hardie <pete.hardie at gmail.com> wrote:
>> > sed -i replaces the file inline - test it well before you deploy, as
>> > if it screws up, you no longer have the original to go back to

There are a few ways around that.

What you can do is something like:

 $ sed -i.orig 's$foo$bar$g;' *

And it will move the original to ${NAME}.orig so that you can revert it
if necessary.  Another way is to leverage a tool like git to make
temporary changes, e.g.:

 $ git init .
 $ git add .
 $ git ci -m 'Initial commit'
 $ sed -i 's$foo$bar$g;' *
 $ git diff

Then when you're done, just:

 $ rm -Rf .git

And you're good.  That way you can see what the changes do and if
necessary, clean up any corner cases with relative ease.

Useful if you have to do a lot of ad-hoc modifications.

	--- Mike

-- 
A man who reasons deliberately, manages it better after studying Logic
than he could before, if he is sincere about it and has common sense.
                                   --- Carveth Read, “Logic”


More information about the Ale mailing list