Inserting into a file

Hi,
I have a file which looks something like

#group1{
a
b
c
d}

#group2{
a
d
1
2
3
}

#group3{
x
y
u
}

Im trying to insert into this file a line under a specified group (or #groupx{ ). So if i say insert g into group2 it will turn the file into:


#group1{
a
b
c
d
#group1}

#group2{
g
a
d
1
2
3
#group2}

#group3{
x
y
u
#group3}

what Im looking for is a way of doing this in a single line. Can anyone help me with this?
Thanks!
LVL 2
TraltixxAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
perl -i -pe '$_.="g\n" if /#group2\{/' file
0
All Courses

From novice to tech pro — start learning today.