Insert multiple lines into a file after specified pattern using shell script
Another sed
,
sed '/cdef/r add.txt' input.txt
input.txt:
abcdaccdcdeflineweb
add.txt:
line1line2line3line4
Test:
sat:~# sed '/cdef/r add.txt' input.txtabcdaccdcdefline1line2line3line4lineweb
If you want to apply the changes in input.txt
file. Then, use -i
with sed
.
sed -i '/cdef/r add.txt' input.txt
If you want to use a regex as an expression you have to use the -E
tag with sed
.
sed -E '/RegexPattern/r add.txt' input.txt