[英]Replace text between 2 particular lines in a text file using sed
有人问过类似的问题,但它们是针对Powershell的。
我有一个Markdown文件,例如:
.
.
.
## See also
- [a](./A.md)
- [A Child](./AChild.md)
.
.
.
- [b](./B.md)
.
.
.
## Introduction
.
.
.
我希望在## See also
和## Introduction
之间将所有出现的.md)
替换为.html)
。
.
.
.
## See also
- [a](./A.html)
- [A Child](./AChild.html)
.
.
.
- [b](./B.html)
.
.
.
## Introduction
.
.
.
我在Bash中尝试过这样
orig="\.md)"; new="\.html)"; sed "s~$orig~$new~" t.md -i
但是,这将替换文件中的所有位置。 但我希望替换只发生在## See also
和## Introduction
你能建议改变吗? 我正在使用awk和sed,因为我对此不太熟悉。 我也知道一些Python,是否建议在Python中进行此类脚本编写(如果对于sed或awk而言过于复杂)?
$ sed '/## See also/,/## Introduction/s/\.md/.html/g' file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.