Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed match multiple lines and then append

Tags:

sed

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
);

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 ");"

The command:

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
like image 936
Alex Avatar asked Oct 23 '25 17:10

Alex


1 Answers

This might work for you:

sed '/^module/,/);/!b;/);/a\NEWCODE' file
like image 61
potong Avatar answered Oct 27 '25 04:10

potong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!