Reputation: 35
I have multiple file which looks like following
module (
input a;
output b;
);
xx inst_xx (
.in (xxin),
.ou (xxou)
);
assign a = b;
endmodule
I want to append a line after ONLY after first occurrence of );
pattern
`include "defines.vh"
so finally it should look like
module (
input a;
output b;
);
`include "defines.vh"
xx inst_xx (
.in (xxin),
.ou (xxou)
);
assign a = b;
endmodule
Anything using sed
or awk
would be useful.
Upvotes: 2
Views: 1309
Reputation: 58351
This might work for you (GNU sed):
sed $'/);/{a`include "defines.vh"\n;:a;n;ba}' file
or:
sed -e '/);/{a`include "defines.vh"' -e ':a;n;ba}' file
This matches the first );
and appends the required string then reads and prints the remainder of the file looping on the n
command.
Upvotes: 1
Reputation: 10865
$ awk '{ print } !flag && /);/ { print "`include \"defines.vh\""; flag = 1 }' file
module (
input a;
output b;
);
`include "defines.vh"
xx inst_xx (
.in (xxin),
.ou (xxou)
);
assign a = b;
endmodule
Upvotes: 1