I’m trying to pass external variable into awk using awk -v
but just cannot figure out what’s my problem!
for ((c=1;c<=22;c++));do cat hg19.gap.bed|awk -v var={chr"$c"} '{if ("$1"=="$var") print}' > $var.cbs;done
What’s the problem of this command?
thx
In awk, only the field variables start with a
$. And you don’t want the double quotes within awk. Tryif ($1 == var) ....Using
$varactually means the field at the index stored invar, in this case not a valid field (but you can use it to iterate over the fields).