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.
Instead of:
awk -F, '$5 == $oid' "$SYMBOL_CSV_FILE"
use it like this:
awk -F "," -v oid="$oid" '$5 == oid' "$SYMBOL_CSV_FILE"
For bash to interpret your variables, you have to use the double quotes. Single quotes will send $oid as is to your program.
Then, as the $5 will also be interpreted, and you don't want to! You have to escape the $.
In the end, you have:
awk -F, "\$5 == $oid" "$SYMBOL_CSV_FILE"
^^ ^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With