使用 awk/nawk,如何找到最大和最小貢獻並列印這些值?
輸入檔:
Name: Phone:1st:2nd:3rd contribution
Mike Harrington:(xxx) xxx-xxxx:250:100:175
Christian Dobbins:(xxx) xxx-xxxx:155:350:201
Susan Dalsass:(xxx) xxx-xxxx:280:60:50
Archie McNichol:(xxx) xxx-xxxx:250:100:175
預期結果最大值 = $350,最小值 = $50
答案1
嘗試這樣做:
awk -F: '
NR>1{
for (i=3; i<NF+1; i++) {
if ($i > max) {
max=$i
}
else if ($i < min || min == 0) {
min=$i
}
}
}
END{
print "max = $" max " and min = $" min
}
' file.txt