对sed1line中一些命令的理解 二

xiaoxiao2022-10-03  446

 

# insert a blank line above every line which matches "regex" #在每个含有字符串regex的行上插入一行空白行 sed '/regex/{x;p;x;}'

 

复习下x ,p命令x   Exchange the contents of the hold and pattern spaces.P   Print the current pattern space.

 

脚本工作流程:

当读入匹配RE的那一行时,       pattern space:  regex      hold space :  blank

先执行x,此时      pattern space: blank      hold space : regex

继续执行p,空行被打印出来      pattern space: blank      hold space : regex

往下执行x      pattern space: regex      hold space : blank

到脚本底,执行默认输出regex,读入下行继续处理。

这样就在每个含有字符串regex的行上插入一行空白行。

 

 

转载请注明原文地址: https://www.6miu.com/read-4977993.html

最新回复(0)