[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Perl or Python for editing files...
- Subject: [ale] Perl or Python for editing files...
- From: mike at trausch.us (Michael Trausch)
- Date: Tue, 18 Oct 2011 13:05:05 -0400
- In-reply-to: <CAPfJb3rxNuqpCAPc10eT0PbTROhjNw8YDSR9J70LXsM=h0oUUw@mail.gmail.com>
- References: <CAPfJb3pvh4t6Vi40hHH4=oTGW20s8kKqaTERWcb1dwc7Y8p-rg@mail.gmail.com> <[email protected]> <CAPfJb3qJ65YQ8AgAxRADwM3qU6qArNqGZZTacmXKHPw=yaqJDA@mail.gmail.com> <CAMdBqcMp+fdNzfGT0j0d5HU3SHkOnWM1Q_BJ0sN08JAzJqXSnA@mail.gmail.com> <CAPfJb3rxNuqpCAPc10eT0PbTROhjNw8YDSR9J70LXsM=h0oUUw@mail.gmail.com>
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?