I am trying to print text between two variables in a file
I have tried the following things but none seem to work:
awk ' /'$a'/ {flag=1;next} /'$b'/{flag=0} flag { print }' file
and also
sed "/$a/,/$b/p" file
But none seem to work
Any Ideas?
Thanks in Advance
yazu
2
awk ' /'"$a"'/ {flag=1;next} /'"$b"'/{flag=0} flag { print }' file
1 Like
Thanks Yazu
This works!!!
i guess, you need to use -v in awk for define the variable and its value and use inside the awk
Hi itkamaraj can you give an example of how to use -v in awk?
yazu
6
Like this:
awk -va="$a" -vb="$b" 'a {flag=1;next} b {flag=0} flag { print }' file
It's more safe and less cumbersome. Of course the names of these variables (in -vVAR="$SHELL_VAR") may be any.