如何对齐下面显示的最小值和最大值
{
for(i = 1; i <= NF; i++)
{
a[i] = $i;
if (min[i]==""){ min[i]=$i;} #line1
if (max[i]==""){ max[i]=$i;} #line2
if ($i<min[i]) { min[i]=$i;} #line3
if ($i>max[i]) { max[i]=$i;} #line4
}
print $0;
}
END {
OFS="\n";
for(j = 1; j <= NF; j++)
{
print min[j],max[j];
}
}
4 14 24 34
3 13 23 33
1 11 21 31
2 12 22 32
5 15 25 35
4 14 24 34
3 13 23 33
1 11 21 31
2 12 22 32
5 15 25 35
1
5
11
15
21
25
31
35
4 14 24 34
3 13 23 33
1 11 21 31
2 12 22 32
5 15 25 35
1 11 21 31 -> Min Values(for that field)
5 15 25 35 -> Max Values(for that field)
答案 0 :(得分:2)
你需要循环两次,一次为最小值,一次为最大值:
END {
for(j = 1; j <= NF; j++) printf "%d ", min[j]
print ""
for(j = 1; j <= NF; j++) printf "%d ", max[j]
print ""
}