All is said in the title , I want to replace all lines between two patterns with a a file content.
file1
line 1
line 2
foo
foobar
bar
line 6
line 7
file2
line 3
line 4
line 5
desired file
line 1
line 2
line 3
line 4
line 5
line 6
line 7
Tried many sed commands nothing works for me , closest command below successfully matchs lines between foo and bar but replace them with "$(cat file2)" string and not file content.
sed '/foo/{:a;N;/bar/!ba;N;s/.*\n/$(cat file2)/};p' file1
printf '%s\n' "$(sed '/^foo$/,$d' file1 && cat file2 && sed -e '/^bar$/,$!d' -e '/^bar$/d' file1)" > desired-file
or(sed '/^foo$/,$d' file1 && cat file2 && sed -e '/^bar$/,$!d' -e '/^bar$/d' file1) > desired-file