【发布时间】:2017-09-27 18:07:15
【问题描述】:
我有一个大文件,内容由标题分隔。
如何通过 sed 或 awk 替换文件中特定标题之后的行和特定字符串(不包括在内)之前的行之间的文本?
示例:我想在下面的文件中将header1 之后的行和string_near_end_of_file 之前的行(不包括)之间的文本替换为EXAMPLE...
...
header1
#######
content1
header2
#######
content2
...
string_near_end_of_file
...
预期结果:
...
header1
#######
EXAMPLE
string_near_end_of_file
...
我知道 sed '/pattern1/,/.. pattern2/c\substition_string' 文件替换 pattern1 和 pattern2 之间的 substition_string 并且 sed -n '/pattern/{n;p}' file 在 pattern 匹配之后打印该行,但我现在不确定是否将其放在一起以实现我的规定的目标。
任何帮助将不胜感激!
【问题讨论】: