[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Importing Shell Variables in to awk from Shell Scripts



Martin McCormick <martin@dc.cis.okstate.edu> writes:

> "Bruno Hertz" writes:
>>The last point applies, because it's not about importing shell
>>vars, but your awk syntax is wrong. Your first example is almost
>>correct, though. Just decide whether you want string comparison
>>or regex match:
>>
>>awk '($6 == "'"$searchvar"'") {print $0}' "$inputfile"
>>awk '($6 ~ /'"$searchvar"'/) {print $0}' "$inputfile"
>
> 	Thank you.  It is string matching I am doing here, but the big
> mistake was in failing to escape the single quote with double quotes.
> The shell ate them, ruining the syntax.

Well, not precisely. The syntax requires slashes // with regex matching ~,
and quotes "" with string comparison == . You did slashes with string
comparison, and that was the primary mistake.

Regards, Bruno.



Reply to: