簡體   English   中英

awk 打印與特定最后一條記錄關聯的字段

[英]awk print the field associated with specific last record

我有一個關於 awk 打印的問題。

這是我的簡要數據文件格式

$cat file.dat

1 3 5 7 9
2 3 7 5 9
7 8 2 4 6
0 2 0 3 4

我想使用“awk”打印列如果第n列的最后一條記錄值大於0,

喜歡這個表格

$cat file2.dat

3 7 9
3 5 9 
8 4 6
2 3 4

我怎樣才能做到這一點?

awk -v col=3 '$NF > 0 { print $col }' file

使用變量 col 指定要打印的列。 然后當最后一列條目($NF)大於0時,打印col指定的列的條目($col)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM