use of variables in awk to search for pattern from a file

Hi,

I need to extract all the content between two strings stored in two variables "startstring" and "endstring"

startstring=hello
enstring=world
#notworking
awk '/$startstring/, $NF ~ /$endstring/ ' file > file2

The above code is not working with variables. It works when actual string values are used as patterns as below.

#workingcode
awk '/hello/, $NF ~ /world/ ' file > file2

Can someone help me to use these two variables in awk for searching the patterns.

Thanks.

Thanks & Regards,
Jean

try this ..

$ v1=hello
$ v2=world
$ nawk "/$v1/,/$v2/" infile
hello
line1
line2
world
$
1 Like

Thanks mate, i never knew an apostrophe would change my life altogether :slight_smile: