[Solved] awk string with spaces

Why does this work:

awk -v s="this is a string" 'index($0, s)' file

while the following doesn't?

s="this is a string"
awk -v s=$s 'index($0, s)' file

How do I search for a string with spaces in it?

---------- Post updated at 01:18 AM ---------- Previous update was at 01:15 AM ----------

I figured it out. Had to use double quotes:

awk -v s="$s" 'index($0, s)' file
1 Like