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でこれを行うことができます:

# 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 に答える
0

perlsed の代わりに、次のようにコマンドラインを使用できます。

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 に答える