如何替换两点之间的所有线并用sed中的某些文本替换它 [英] how to replace all lines between two points and subtitute it with some text in sed
本文介绍了如何替换两点之间的所有线并用sed中的某些文本替换它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这段文字:
BEGIN
hello
world
how
are
you
END
如何在Linux中使用sed命令将其转换为波纹管文本:
How to convert it to bellow text using sed command in linux:
BEGIN
fine, thanks
END
推荐答案
$ cat file
BEGIN
hello
world
how
are
you
END
$ sed -e '/BEGIN/,/END/c\BEGIN\nfine, thanks\nEND' file
BEGIN
fine, thanks
END
/BEGIN/,/END/
选择一个以BEGIN
开头并以END
结束的文本范围.然后c\
命令用于将所选范围替换为BEGIN\nfine, thanks\nEND
.
/BEGIN/,/END/
selects a range of text that starts with BEGIN
and ends with END
. Then c\
command is used to replace the selected range with BEGIN\nfine, thanks\nEND
.
这篇关于如何替换两点之间的所有线并用sed中的某些文本替换它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文