External variable in awk

后端 未结 4 1465
Happy的楠姐
Happy的楠姐 2021-01-07 22:23

I have a script, in which a script snippet is:

x=3
awk \'$2=$x{print $1}\' infile

The external variable is x,

but it p

4条回答
  •  我在风中等你
    2021-01-07 23:05

    awk has a -v option for this purpose, or as @nevelis mentions, just use double quotes:

    awk -v x=3 ' $2==x {print $1} '
    

提交回复
热议问题