Todd Walton wrote:
> I want to use sed to take a config file, find an option in the file
> and change its value, and to leave the file in place.  I want a
> portable, scriptable way to do 'vi settings.config', find setting,
> edit text, ":wq".
> 
> I don't know sed at all, I just know that it does this kind of thing. 
> What's the best way for a new person to approach getting a basic
> understanding of its use?

perl excels at this kind of in-place editing. With sed, you need to
make a copy of the file, use the copy as an input, then write the
changes out to the file itself. With perl, you can specify the file
changes in a sed form, and have perl make the changes in place. You can
also have perl make a backup copy, if that makes you feel safer, all in
one command.

% perl -pi -e 's/(key)=.*/$1=new_value/' file.config
% perl -pi.bak -e 's/(key)=.*/$1=new_value/' file.config

Both of those do the same thing, but the latter will make a copy of the
original file prior to editing. I would recommend reading through the
perlrequick, perlretut, and perlre man pages. They go through regular
expressions quite thoroughly.

-john


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to