sudo perl -e 'open($fh, "<", "/tmp/foo"); @f = <$fh>; close($fh); open($fh,
">", "/tmp/foo"); foreach(@f) { s/^(Key1=).*/$1NewValue1/; print $fh $_; }
close($fh);'

As always, TIMTOWTDI.

HTH,
            -- Eric,

Alpesh Naik <naik.alp...@gmail.com> wrote on 07/09/2009 11:34:43 AM:

> From:>
>
> Alpesh Naik <naik.alp...@gmail.com>
>
> To:
>
> beginners@perl.org
>
> Date:
>
> 07/09/2009 11:35 AM
>
> Subject:
>
> Edit a config file using perl cgi script
>
> Hi,
>
> I need to edit a config file using perl cgi  script. i.e., Search with
the
> 'key' string and edit the 'value'.
>
> For eg: below is what I have in the config file "configfile.cfg".
>
> Key1=OldValue1
> Key2=OldValue2
>
> I want to search for "Key1" and change "OldValue1" to "NewValue1"
>
> *(Note that, permission of config file is 600, i want to edit the file
> without changing permissions)*
>
> Thanks and Regards,
> Alpesh


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to