Greetings to all-
Here's a sample of my csh script that uses nawk to search a datafile.
Everything works fine but I want the part '$5 ~ search' to match the beginning
of the internal variable 'search', kinda like '$5 ~ ^search' but it doesnt
like that. what I ended up doing was changing that part to
' $5 ~ /^'"$opt1"'/ '
That way worked fine using the csh variable. I would rather use the
internal nawk variable (it would seem a bit cleaner). any other suggestions
would be greatly appreciated.
if ($opt1 == "-M" && $?opt2 == 1) then
nawk -F: 'BEGIN {found = 0 ; \
search = toupper(search1)} \
$5 ~ search {found = 1 ; printf ("%-29s%-16s%-7s%-10s%-11s%-7s\n",$1,$2,$6) \
goto bottomQuote:} END {if (found == 0) print "No Matches"}' search1=$opt2 $phonefile
endif
BTW - I tried several other ways. like '/^search/', but then it takes the
variable search literally. how can I tell it that its a variable inside the
'//' 's ? Is there a metacharacter that I overlooked?
-Chris