开发者

how to replace all lines between two points and subtitute it with some text in sed

开发者 https://www.devze.com 2023-02-14 18:14 出处:网络
Suppose I have this text: BEGIN开发者_StackOverflow中文版 hello world how are you END How to convert it to bellow text using sed command in linux:

Suppose I have this text:

BEGIN开发者_StackOverflow中文版
hello
world
how
are
you
END

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/ 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消