sed to Edit INI and Config Files in CI
sed updates key=value settings in INI and properties files by matching the key and replacing the value after the equals sign.
Flat config files map cleanly onto sed. Anchor the key, optionally scope to a section, and the value swap is a one-liner that needs no parser.
What it does
sed matches a key=value line and rewrites the value. To scope a key that appears in several sections, use a range from the section header to the next header. To toggle a key only when present, the plain substitution suffices.
Common usage
# change a top-level key
sed -i 's/^timeout=.*/timeout=30/' app.ini
# change host only inside the [db] section
sed -i '/^\[db\]/,/^\[/s/^host=.*/host=prod.db/' app.ini
# enable a flag
sed -i 's/^debug=false/debug=true/' app.propertiesOptions
| Pattern | What it targets |
|---|---|
| ^key=.* | The full value of key from the line start |
| /^\[sec\]/,/^\[/ | A range scoped to one INI section |
| s/false/true/ | Toggle a boolean value in place |
| append with a | Add a key that is missing under a section |
| ^#key= | Match a commented-out key to uncomment it |
In CI
sed shines on properties and INI files because they are line-oriented. It cannot add a key that does not exist with a plain s command; pair it with the a append command or a grep test, since s only edits lines that already match.
Common errors in CI
Square brackets in a section header are regex metacharacters, so /^[db]/ matches a line starting with d or b, not the literal [db]; escape them as /^\[db\]/. A value containing & is taken as the whole match in the replacement unless you write \&.