根据来自CSV的列值获取行

San*_*ndy 0 awk

我有以下数据的CSV

10.000.00.00,D3,1
10.001.00.00,C4,2
10.002.00.00,C5,2
10.000.88.99,B1,3
10.000.00.00,B2,3
10.000.00.00,C6,3
10.000.99.00,D1,3
Run Code Online (Sandbox Code Playgroud)

尝试下面的代码

cat Data.csv | awk -F , '$3 == "3" { print }'
Run Code Online (Sandbox Code Playgroud)

只需要获取最后值为3的行。

请让我知道该怎么做

Jam*_*own 5

使用awk 仅获取最后值为3的行

$ awk -F, '$NF==3' file
10.000.88.99,B1,3
10.000.00.00,B2,3
10.000.00.00,C6,3
10.000.99.00,D1,3
Run Code Online (Sandbox Code Playgroud)

解释:

awk -F, '  # set the field separator to a comma
$NF==3     # NF is the last field, $NF last field value (see comments for more
' file                                                  #thanks @kvantour)
Run Code Online (Sandbox Code Playgroud)