Artificial intelligent assistant

Filter a row based on field=variable I want to filter on the first field equal to the value of VAR. There is a similar problem here, whose `~` solution (SOL1) I have not been able to reproduce. However, that based on `eval` (SOL2) works, but seems contrived. I'm looking for a solution that is more like SOL1. $ cat tmp a b c d e f g h i $ awk '$1 ~ /d/' tmp d e f $ VAR='d' SOL1 (FAIL) $ awk '$1~VAR' tmp a b c d e f g h i SOL2 (WORKAROUND) $ CMD='awk '"'"'$1'"~/$VAR/'" $ echo "$CMD" awk '$1~/d/' $ eval "$CMD" tmp d e f

Compare strings with `==`.


VAR="d"
awk -v var="$VAR" '$1==var' file


Output:


d e f


* * *

From `man awk`:

> `-v var=val`: Assign the value val to the variable var, before execution of the program begins. Such variable values are available to the BEGIN rule of an AWK program.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2d2377919d5be47713d31ce2611278ec