如何替换两点之间的所有线并用sed中的一些文本替换它 [英] how to replace all lines between two points and subtitute it with some text in sed

查看:14
本文介绍了如何替换两点之间的所有线并用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/cBEGIN
fine, thanks
END' file
BEGIN
fine, thanks
END

/BEGIN/,/END/ 选择以 BEGIN 开头并以 END 结尾的文本范围.然后使用c命令将选中的范围替换为BEGIN fine,Thanks END.

/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 fine, thanks END.

这篇关于如何替换两点之间的所有线并用sed中的一些文本替换它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆