突出显示最后一列中小于所有先前数字的每个数字

突出显示最后一列中小于所有先前数字的每个数字

输入:

network-snapshot-000000        time 6m 40s       fid50k_full 34.9546
network-snapshot-000201        time 6m 52s       fid50k_full 30.8073
network-snapshot-000403        time 6m 51s       fid50k_full 33.3470
network-snapshot-000604        time 6m 51s       fid50k_full 32.7172
network-snapshot-000806        time 6m 49s       fid50k_full 30.3764

输出:

network-snapshot-000000        time 6m 40s       fid50k_full 34.9546
network-snapshot-000201        time 6m 52s       fid50k_full 30.8073*
network-snapshot-000403        time 6m 51s       fid50k_full 33.3470
network-snapshot-000604        time 6m 51s       fid50k_full 32.7172
network-snapshot-000806        time 6m 49s       fid50k_full 30.3764*

答案1

$ awk 'NR == 1 { min = $NF } ($NF < min) { min = $NF; $0 = $0 "*" }; 1' file
network-snapshot-000000        time 6m 40s       fid50k_full 34.9546
network-snapshot-000201        time 6m 52s       fid50k_full 30.8073*
network-snapshot-000403        time 6m 51s       fid50k_full 33.3470
network-snapshot-000604        time 6m 51s       fid50k_full 32.7172
network-snapshot-000806        time 6m 49s       fid50k_full 30.3764*

min如果我们当前正在读取第一行 ( NR == 1),则这会将找到的最小值 初始化为最后一列中的第一个值。然后,对于每个输入行,如果最后一列中的值严格小于我们的min值,则该min值将被替换,并附加当前行*

然后无条件输出每一行。

相关内容