sed script help

I am having a file as stated below :

File 1:

##########################

idnd a 
integer 2;
list 1 ;
list2 ;

chip top alist( .a(1) , .b(2) , .c(3) ,
.d(1) , .e(7) , .n(80),
.d(1) , .g(7) , .n(80),
.f(1) , .e(7) , .m(80));

lis 7 nfj ;
jdjd kn;
jsjd l ;

######################################

I am having another file as stated below

File2

########################3

int y ;
lsi 8 
lis kf l
kd d ;
jdjd l;

dkdk ;

###########################

I want to insert the content of File 2 to File 1 after a pattern match
Pattern to match

chip_top alist till ));

After )); it should insert FILE2 into FILE 1 and create another FILE3
as stated below

FILE 3

#################################


idnd a 
integer 2;
list 1 ;
list2 ;

chip top alist( .a(1) , .b(2) , .c(3) ,
.d(1) , .e(7) , .n(80),
.d(1) , .g(7) , .n(80),
.f(1) , .e(7) , .m(80));

// file 2 content //
int y ;
lsi 8 
lis kf l
kd d ;
jdjd l;

dkdk ;



lis 7 nfj ;
jdjd kn;
jsjd l ;

######################################

I was trying something like this but its not working

sed '/chip_top alist,/));/r  FILE2' FILE1 > FILE3

Could you help me out ??

Try

sed -e '/));/ {p;r file2' -e'}; ' file1
1 Like

Hi Rudic ,

Thanks a lot but in my original file , I am having lots of places where )); is coming so I need to search for the chip_top alist and )); pattern and want to add the FILE3 content after that .

Could you help me out in achieving that ?

Thanks and Regards
Kshitij Kulshreshtha

How about

sed -e '/chip top alist/,/));/{/));/ r file2' -e'}; ' file1

Make sure your regex matches the file's contents (it doesn't in port#1)

1 Like

Thanks Rudic ! It is working perfectly !