I have a file like this (where xxxxn = any random string):
xxxx1
xxxx2
xxxx3
xxxx4
END
xxxx5
xxxx6
xxxx7
END
xxxx8
...
I want to match between a shell variable and the next END. Say the shell variable equals xxxx2, I would like:
xxxx3
xxxx4
I think awk is probably the tool for the job but I'm open to other commands.
I have got it working if I hard code it (with xxxx2 again) like so:
awk '/xxxx2/{flag=1;next}/^END/{flag=0}flag' file
But I would like it to reference a shell variable and the symbols to be escaped. I tried:
awk -v var="$my_var" '/~var/{flag=1;next}/^END/{flag=0}flag' file
(After reading this https://stackoverflow.com/a/39384347/11633601) But that outputs nothing.
Thanks.