3

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

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

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

命令:

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

将“要附加的代码”放在匹配序列中的每一行上,而不仅仅是在它之后

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
4

4 回答 4

3

这可能对您有用:

sed '/^module/,/);/!b;/);/a\NEWCODE' file
于 2012-05-09T23:58:57.817 回答
1

这有点笨拙,但它会完成这项工作:

sed ':a /module/s/);/);\ncode to append/;t;N;b a' filename
于 2012-05-09T22:37:01.960 回答
0

您可以使用这样的命令行来代替 sed perl

perl -0pe 's@(module[^(]*\([^)]*\)\s*;)@$1'"\na code to append"'@' test.v

输出

module module_name (
input wire in1,
input wire in2,
output wire out1
);
a code to append
于 2012-05-09T22:35:36.887 回答
0

既然你说 sed 或任何其他命令,我会用 perl 回答。您可以在 perl 中使用以下命令执行此操作:

# perl -pe 'BEGIN { $/ = undef; }s#(^module.+?\);)#$1\ncode to append#omgs' test.v

module module_name (
input wire in1,
input wire in2,
output wire out1
);
code to append
于 2012-05-09T22:46:35.007 回答