Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My configuration file, server.conf, has the following format



How do I add an additional setting to the "general" stanza using a bash script?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You could do it with sed

$ sed 's/^\[general\]/\[general\]\nnew=setting/' file 

which adds new=setting after the [general]. using sed -i.bak ... file will do it in place and create a file.bak for safety.

share|improve this answer

This seems to be mostly answered over on stackoverflow:

Basically its a job for SED or AWK and a little regex.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.