我想使用shell脚本在文件中插入多行.
abcd
accd
cdef
line
web
现在我必须在input.txt文件中的"cdef"行之后插入四行.
abcd
accd
cdef
line1
line2
line3
line4
line
web
上面的插入我应该使用shell脚本来完成.有人能帮我吗?
我想使用shell脚本在文件中插入多行.
abcd
accd
cdef
line
web
现在我必须在input.txt文件中的"cdef"行之后插入四行.
abcd
accd
cdef
line1
line2
line3
line4
line
web
上面的插入我应该使用shell脚本来完成.有人能帮我吗?
还有sed
个,
sed '/cdef/r add.txt' input.txt
输入txt:
abcd
accd
cdef
line
web
添加txt:
line1
line2
line3
line4
Test:
sat:~# sed '/cdef/r add.txt' input.txt
abcd
accd
cdef
line1
line2
line3
line4
line
web
如果要在input.txt
文件中应用更改.然后,使用-i
和sed
.
sed -i '/cdef/r add.txt' input.txt
如果你想使用正则表达式,你必须使用-E
标记和sed
.
sed -E '/RegexPattern/r add.txt' input.txt