What would be the sed command for mac shell scripting that would replace all iterations of string “fox” with the entire string content of myFile.txt.
myFile.txt would be html content with line breaks and all kinds of characters. An example would be
</div>
</div>
<br>
<div id="container2">
<div class="question" onclick="javascript:show('answer2')";>
Thanks!
EDIT 1
This is my actual code:
sed -i.bkp '/Q/{
s/Q//g
r /Users/ericbrotto/Desktop/question.txt
}' $file
When I run it I get:
sed in place editing only works for regular files.
And in my files the Q is replaced by a ton of chinese characters (!). Bizarre!
You can use the
rcommand. When you find a ‘fox’ in the input……replace it with the empty string…
…and read the input file:
If you have a file such as:
the result is:
EDIT: to alter the file being processed, just pass the
-iflag to sed:Some sed versions (such as my own one) require you to pass an extension to the
-iflag, which will be the extension of a backup file with the old content of the file:And here is the same thing as a one liner, which is also compatible with Makefile