文件.txt 包含
a,b,yes
x,y,no
awk -F',' '($3 == "是")' file.txt
a,b,yes
当我在 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
答案1
awk -F',' -v res=no '($3 == res)' file.txt
x,y,no
或者
res=yes
awk -F',' "(\$3 == \"$res\")" file.txt
a,b,yes