Sluggers,

Does anyone know how to use an argument to awk as a pattern match?

I.E

#!/bin/bash
#
SEARCH="SomeString"
awk  --assign search=$SEARCH '
BEGIN { printf("Search:%s\n",search) }
/search/ { printf("%s\n",$0) }'

The printf statement produces "SomeString" as expected but not surprisingly the '/search/' pattern matches "search". How can I make awk understand that I want to use the value of the variable 'search' not the literal string?

TIA's

P.

P.S Yes perl heads feel free to use the opportunity to show the mastery of perl over awk ;-)


-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to