I want to pass 2 shell (bash) variables from into an awk statement. In this example the variables are marker1 and marker2
ubuntu@ubuntutest:/tmp$ echo $marker1
###___showhost___###
ubuntu@ubuntutest:/tmp$ echo $marker2
###___showhostset___###
ubuntu@ubuntutest:/tmp$
The script will extract all the lines of text between to different strings/markers ($marker1 and $marker2) from text file - file.in
ubuntu@ubuntutest:/tmp$ cat file.in
###___showhost___###
Id Name Persona -WWN/iSCSI_Name- Port
115 server5295 VMware 5005638024D3E8E6 1:2:4
116 server5296 VMware 5005638024D3EA86 1:2:4
117 server5297 VMware 5005638024D3F5D2 1:2:4
142 server5302 VMware 5005638024D3E8B6 1:2:4
143 server5303 VMware 5005638024D3E9C6 1:2:4
144 server5304 VMware 5005638024D3F4F2 1:2:4
###___showhostset___###
Id Name Members
0 Mgt_Stack server5295
1 Cluster1 server5302
server5304
ubuntu@ubuntutest:/tmp$
If I run the awk statement, where I use the actual string values for variables marker1/marker2 ###___showhost___### and ###___showhostset___### respectively instead of using the variables themselves (within awk) I get a positive result. However, I want to put the awk statement in a bash scripts and need to read the variables marker1/marker2.
ubuntu@ubuntutest:/tmp$ awk '/^###___showhost___###/{flag=1;next}/^###___showhostset___###/{flag=0}flag' file.in
Id Name Persona -WWN/iSCSI_Name- Port
115 server5295 VMware 5005638024D3E8E6 1:2:4
116 server5296 VMware 5005638024D3EA86 1:2:4
117 server5297 VMware 5005638024D3F5D2 1:2:4
142 server5302 VMware 5005638024D3E8B6 1:2:4
143 server5303 VMware 5005638024D3E9C6 1:2:4
144 server5304 VMware 5005638024D3F4F2 1:2:4
ubuntu@ubuntutest:/tmp$
However, when i use the 2 variables $marker1 and $marker2 in the awk statement I get no output.
ubuntu@ubuntutest:/tmp$ awk '/^"'$marker1'"/{flag=1;next}/^"'$marker2'"/{flag=0}flag' file.in
ubuntu@ubuntutest:/tmp$
Any help greatly appreciated !!!