[ale] Perl or Python for editing files...
Pete Hardie
pete.hardie at gmail.com
Mon Oct 17 14:59:26 EDT 2011
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
On Mon, Oct 17, 2011 at 14:35, Chuck Payne <terrorpup at gmail.com> wrote:
> On Mon, Oct 17, 2011 at 2:17 PM, Jim Lynch
> <ale_nospam at fayettedigital.com> wrote:
>> On 10/17/2011 02:01 PM, Chuck Payne wrote:
>>> Guys,
>>>
>>> I have four files I like to be able to edit from a script. I have
>>> heard that it's better to use Perl or Python to this than bash.
>>>
>>> I am new to be perl and python from a scripting. What would be easy? I
>>> know it question that would open up a larger debate, but I really need
>>> help on this.
>>>
>>> If you recommend one of the two can you show me a site that explain
>>> how to open and write the files.
>>>
>>>
>>> Thanks,
>>>
>> It really depends on the complexity of the edit task. A combination of
>> bash, sed and awk can do simple edits, driving ex with bash can do a bit
>> more complex operations, but perl or python would be best for really big
>> editing jobs. So to answer your question give us a real world example
>> of what you want to do. What's the input and the desired output?
>>
>> Jim.
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
>
> I want to build a script that would let me edit a kvm clone. I want to
> script to be able to edit let say /etc/hosts and couple other file, I
> want to replace ip and host name. So that I can make deploy easier and
> I don't have to touch all the files I need too.
>
> I guess if I could do with bash/sed/awk that work, the problem is how
> to do. I know how to use sed to change and write out a new file, but I
> rather just be able to edit the same file and save it.
>
> --
> (678) 636-9678
> -----------------------------------------
> Discover it! Enjoy it! Share it! openSUSE Linux.
> -----------------------------------------
> openSUSE -- en.opensuse.org/User:Terrorpup
> openSUSE Ambassador/openSUSE Member
> skype,twiiter,identica,friendfeed -- terrorpup
> freenode(irc) --terrorpup/lupinstein
> Register Linux Userid: 155363
>
> Have you tried SUSE Studio? Need to create a Live CD, an app you want
> to package and distribute , or create your own linux distro. Give SUSE
> Studio a try. www.susestudio.com.
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
--
Pete Hardie
--------
Better Living Through Bitmaps
More information about the Ale
mailing list