shell - How to extract string between two regexes passed as variables to awk? -
i'm trying extract text in passage between 2 strings being saved in variables. wrong following way?
input:
module dft ( a, b, c, clk, z, test_si, test_se ); input [7:0] a; dft_dw_mult_uns_1 mult_31 ( .a(a), .b(b), .product(reg0) ); endmodule
output:
input [7:0] a; dft_dw_mult_uns_1 mult_31 ( .a(a), .b(b), .product(reg0) );
using following code:
try="module dft"; awk '/$try/{flag=1; next} /endmodule/{flag=0} flag' dft_syn.v
but doesn't recognize $try variable.
you can use awk
this:
sm="module dft" em="endmodule" awk -v sm="$sm" -v em="$em" '$0 ~ em{p=0} p; $0 ~ sm{p=1}' file
...which property emits output:
input [7:0] a; dft_dw_mult_uns_1 mult_31 ( .a(a), .b(b), .product(reg0) );
- use
-v var="value"
pass command line variables shellawk
- set , reset variable
p
when encounter start or end tags
Comments
Post a Comment