I have a question about awk print.
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,
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. Then when the last column entry ($NF) is greater than 0, print the entry of the column specified by col ($col)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.