sed 匹配多行然后追加 [英] sed match multiple lines and then append

查看:144
本文介绍了sed 匹配多行然后追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 verilog 端口列表后附加一些代码,格式如下:

I want to append some code after a verilog port list, which has the form:

module module_name (
input wire in1,
input wire in2,
output wire out1
);

我正在寻找有关如何使用 sed(或其他命令)查找以module"开头并以);"结尾的端口列表的帮助;然后在);"后面的行中添加一些代码

I'm looking for help on how to use sed (or another command) to find the port list starting with "module" and ending with ");" and then append some code on the line following ");"

命令:

sed '/^module/,/);/a code to append' test.v

在匹配序列中的每一行上放置要追加的代码",而不仅仅是在它之后

puts "code to append" on every line within the matched sequence and not only after it

module module_name (
code to append
input wire in1,
code to append
input wire in2,
code to append
output wire out1
code to append
);
code to append

推荐答案

这可能对你有用:

sed '/^module/,/);/!b;/);/a\NEWCODE' file

这篇关于sed 匹配多行然后追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆