I’m trying to update a configuration file using perl, I’ve come up with a way to read the file in and update key value pairs. However, i’d like to improve it by prepending matches with # and then inserting the string in the line below
Existing script:
local($^I, @ARGV) = ("sourcefile");
while (<>) {
s,^key1=.*$,key1=value1,;
s,^key2=.*$,key2=value2,;
s,^key3=.*$,key3=value3,;
print;
close ARGV if eof;
}
Desired result:
file before:
key1=value1
key2=value2
key3=value3
file after:
key1=value1
#key2=value2
key2=test
key3=value3
1 Answer