0

I write a bash script to replace the keyword with the whole content of another file. Here is the command I use:

sed -i "s/CONTENT/$(cat $pathB)/" $pathA

A file

Here is my introduction:
CONTENT
Thank you.

B file

I'm OOO.
I'm 10 years old.
I like play baseball

Result A file

Here is my introduction:
I'm OOO.
I'm 10 years old.
I like play baseball
Thank you.

But this will show error:

sed: -e expression #1, char 14: unknown option to `s'

What am I doing wrong?

Azreal
  • 45

1 Answers1

1

You can use the r command to append the content of file then delete the line containing the pattern:

sed -i -e "/CONTENT/r $pathB" -e '//d' $pathA

The reason why your s command fail is because it is expanded to:

sed 's/CONTENT/Im OOO.
Im 10 years old.
I like play baseball' $pathA

s.ouchene
  • 321