sed -i "/xxxxxxxxxxxx/r inc-sausage" git.html
sed -i "/xxxxxxxxxxxx/d" git.html
First I insert the content of inc-sausage when xxxxxxxxxxxx is found
Second I delete xxxxxxxxxxxx
Both commands do exactly what I want. But how can I combine both sed commands to a single one? I tried
sed -i "s/xxxxxxxxxxxx/r inc-sauasge" git.html
For starters, you coould concatenate both sed
commands into one line and avoid repeating the search string, like this:
sed -i -e "/xxxxxxxxxxxx/r inc-sausage" -e "//d" git.html
Also, if you want to delete xxxxxxxxxxxx
only and not other things in its line, you could do that instead:
sed -i -e "/xxxxxxxxxxxx/r inc-sausage" -e "s///" git.html
This might work for you:
sed -i '/xxxxxxxxxxxx/{r inc-sausage'$'\n''d}' git.html
Explanation:
See here why $'\n'
is necessary. Also note that d
command must be last as it deletes the pattern space and then immediately starts the next cycle.
Or for GNU sed:
sed -i '/xxxxxxxxxxxx/s|.*|cat inc-sausage|e' git.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With