Problem using variable inside awk

HI,
This is the code I am using:

awk -v aaa="connect" 'BEGIN {IGNORECASE} /aaa/,/!/ {print NR}' bb

This does not throw any error but it does not work. Pls help

Thanks.

Assuming you're using gawk, IGNORECASE must be set to true, something like:

IGNORECASE=1
awk -v aaa="connect" 'tolower($0)~aaa,/!/{print NR}' bb

If you're using gawk, you could also use the -i switch for case-insensitive.

Another alternative:

$ aaa="connect"
$ awk 'BEGIN{IGNORECASE=1} /'$aaa'/,/!/ {print NR}' bb

Thanks a lot for all your replies. Now it works fine :slight_smile: