copy file content to target file. After last match of pattern in target file. Content from original filed displays on next line of target file

I have two files,
file.1
 $ cat file.1 
this is the stuff that needs to be copied.
and file.2
$ cat file.2
aaaa
aaaa
aaaa
aaaa

bbbb
bbbb
bbbb
bbbb

cccc
cccc
cccc
cccc

dddd
dddd
dddd
dddd

I would like to *copy the contents of file.1 to file.2 after the last match of bbbb.

so it would be something along the lines of:
cat file.1 >> file.2

but that only appends to the end of the file, so maybe
cat file.1 >> file.2 | grep bbbb

but that doesn't work like I would like.

The outcome should be:

$ cat file.2
aaaa
aaaa
aaaa
aaaa

bbbb
bbbb
bbbb
bbbb
this is the stuff that needs to be copied.

cccc
cccc
cccc
cccc

dddd
dddd
dddd
dddd


Source: linux

Leave a Reply