grep/sed query

Hi all,
I have one query,in my script,i give one input like sectionname that enclose with[] and that will search in specific file in specific directory.If found ,then it's search next [ or eof ,if found,just decrease line no. and insert lines. like example..
in common.cfg file under config directory.i want to insert some parameter's in last of [CHECKPORT] section and begin of [sometext] section ,sometext means different sectionname.

[CHECKPORT]
p1
p2
p3
[section2]
p4
p5
p6

I want to insert parameter's below p3.

I did like this....

N=$(grep -Fwnx "$SECT" $FILE | cut -d ':' -f1)
((N++))
sed -i"{$N}" 'i\' "common.cfg [CHECKPORT] parameter9" config

this code inside loop.

Thanks
surya

---------- Post updated at 06:52 AM ---------- Previous update was at 05:32 AM ----------

Hi all,
let me revise my query,
Actually :- grep -Fwnx "[CHECKPORT]" common.cfg | cut -d ':' -f1 line of code find the line number of checkport section in common.cfg file and
((N++))---->increase the line number
sed -i"{$N}" 'i\' "common.cfg [CHECKPORT] parameter9" inputfile ,insert parameter.

In this code,it's simply add parameter's in begin of checkport section but i need it should insert at end of section.

Thanks
surya

Why not just sed:

 
sed '
  s/\[CHECKPORT\].*/&\
new-line-of-data/
 ' common.cfg >common.cfg2

PS: [ is a regex meta character.

HI DGPickett,
This line of code simply substitue the section to new parameter.
I nedd parameter should written at the end of section.

Thnaks
surya