[英]awk print the field associated with specific last record
I have a question about awk print.我有一个关于 awk 打印的问题。
here's my brief data file format这是我的简要数据文件格式
$cat file.dat
1 3 5 7 9
2 3 7 5 9
7 8 2 4 6
0 2 0 3 4
I want to print the column using "awk" If the last record value of the n-th column is greater than 0,我想使用“awk”打印列如果第n列的最后一条记录值大于0,
like this form喜欢这个表格
$cat file2.dat
3 7 9
3 5 9
8 4 6
2 3 4
How can I do this?我怎样才能做到这一点?
awk -v col=3 '$NF > 0 { print $col }' file
Specify the column to print using the variable col.使用变量 col 指定要打印的列。 Then when the last column entry ($NF) is greater than 0, print the entry of the column specified by col ($col)然后当最后一列条目($NF)大于0时,打印col指定的列的条目($col)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.