how to replace all lines between two points and su

2020-07-03 04:17发布

Suppose I have this text:

BEGIN
hello
world
how
are
you
END

How to convert it to bellow text using sed command in linux:

BEGIN
fine, thanks
END

标签: linux sed
2条回答
迷人小祖宗
2楼-- · 2020-07-03 04:30
sed -e 's/BEGIN hello world how are you END/BEGIN fine, thanks END/g'
查看更多
聊天终结者
3楼-- · 2020-07-03 04:47
$ 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/ 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.

查看更多
登录 后发表回答