AWK with a variable - am I missing something??

I've got a file - for example:

A B C D E
21134570 1 21573 XXXX XXXX
21134570 1 21574 XXXX XXXX
21134570 1 21575 XXXX XXXX
21134577 1 21569 XXXX XXXX
21134571 1 21566 XXXX XXXX
21134566 1 21536 XXXX XXXX
21134560 1 21555 XXXX XXXX

I have a line of code that will get a value from column "A" based on some other requirements (stored in variable: CurrentAValue)

I want to get column C value for the current A value

I've tried:

var=`awk '$1 ~ $CurrentAValue { print $3 }' $FILE | sed -n "$1 p"`

Am I missing something? It won't work correctly.
I'v also tried
awk -v val=$CurrentAValue '$1 ~ $val { print $3 }' $FILE | sed -n "$1 p"`
and it gives me an error stating that val must be between 0 and 199

I've tried many things:
$1 ~ /$CurrentAValue/
$1 ~ "/$CurrentAValue/"
$1 ~ /"$CurrentAValue"/

What am I missing? I'm sort of new to shell scripting so I'm sure there is just something I'm not aware of.

Thanks for any help!!

awk -v val="${CurrentAValue}" '$1 ~ val { print $3 }' $FILE 

Hmmm, I tried that and it is still giving me the :
awk: The field 25052601 must be in the range 0 to 199. (obviously I have a larger file than the example shown above so the "field" value is the CurrentAValue)

oops - my bad. i still had the "$" in from of the val part
it worked now

THANKS!!! :slight_smile:

okie.............