0

file.txt contains

a,b,yes
x,y,no

awk -F',' '($3 == "yes")' file.txt

a,b,yes

when I use variable in awk

res=yes
awk -F',' "($3 == "$res")" file.txt

awk: cmd. line:1: ( == yes) 
awk: cmd. line:1:   ^ syntax error 
awk: cmd. line:2: ( == yes) 
awk: cmd. line:2:         ^ unexpected newline or end of string
3
awk -F',' -v res=no '($3 == res)' file.txt
x,y,no

or

res=yes
awk -F',' "(\$3 == \"$res\")" file.txt
a,b,yes
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.