I want to edit a file using sed/awk. The file is made up of several configuration sections, like this:
SECTION 1 BEGIN
some stuff
SECTION END
SECTION 2 BEGIN
some stuff
some more stuff
important line
SECTION END
I want to add important line
to the end of SECTION 2
if it doesn't already exist, preferably as a command one liner. I've been looking at the fgrep/sed combo in this question, but I don't quite understand how to adapt it for what I need.
Note: there may be blank lines in the sections.
Many thanks.