使用 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