I am trying to find the text between the two lines, the starting line contains an index(variable), so I need to pass it from shell to awk. But I am not able to figure out how to mix /start/,/end/ construct with variables.
This is the input data:
echo "$x"
abc def 1
hey there
end
abc def 2
hello there
whats up
end
abc def 3
howdy
end
This works fine, but it is hard coding the index(Eg 2)
echo "$x" |awk '/abc def 2/,/end/'
abc def 2
hello there
whats up
end
Some naive attempts:
-->echo "$x" |awk -vnum=2 '/abc def /2,/end/'
abc def 1
hey there
end
abc def 2
hello there
whats up
end
abc def 3
howdy
end
-->echo "$x" |awk -vnum=2 'BEGIN{start="abc def "num}start,/end/'
abc def 1
hey there
end
abc def 2
hello there
whats up
end
abc def 3
howdy