Execute a cat command within a sed command in Linux Execute a cat command within a sed command in Linux linux linux

Execute a cat command within a sed command in Linux


How about saving the content of the file in the variable before inserting it into sed string?

$content=`cat file.txt`; sed "s/%d/${content}/g file1.txt"


Given original.txt with content:

this is some text that needs replacement

and replacement.txt with content:

no changes

I'm not sure what your replacement criteria is, but lets say I want to replace all occurrences of the word replacement in the original file, you may replace the content of the original text with the content of the other file using:

> sed -e 's/replacement/'"`cat replacement.txt`"'/g' original.txtthis is some text that needs no changes


You can read a file with sed using the r command. However, that is a line-based operation, which may not be what you're after.

sed '/%d/r file1.txt'

The read occurs at the end of the 'per-line' cycle.