Awk not working in bash script when use variable in comparison

bash, linux, shell

Solution

Instead of:

awk -F, '$5 == $oid' "$SYMBOL_CSV_FILE"

use it like this:

awk -F "," -v oid="$oid" '$5 == oid' "$SYMBOL_CSV_FILE"

Problem

Following is my bash script. If I use varible oid to compare in awk, it doesnt show matching line. ``` oid="3586302804992" SYMBOL_CSV_FILE="symbol/BAC" awk -F, '$5 == $oid' "$SYMBOL_CSV_FILE" echo "2nd" awk -F, '$5 == "3586302804992"' "$SYMBOL_CSV_FILE" ``` O/P is ``` 2nd BAC,1,O,1,3586302804992 ``` `symbol/BAK` file contents are ``` BAC,1,O,1,3586302804992o ``` Putting "" around $oid , on 3rd line, doesnt make any difference.

Original source