When the replacement string has newlines and spaces, you can use something else. We will try to insert the output of ls -l
in the middle of some template file.
awk 'NR==FNR {a[NR]=$0;next}
/Insert index here/ {for (i=1; i <= length(a); i++) { print a[i] }}
{print}'
<(ls -l) text.txt
When you want something inserted after a line, you can move the command {print}
or switch to :
sed '/Insert command output after this line/r'<(ls -l) text.txt
You can also use sed for inserting before a line with
sed 's/Insert command output after this line/ls -l; echo "&"/e' text.txt