需求
文本如下:
[root@localhost ~]#cat urfile
1 1 2
1 2 1
1 3 1
[root@localhost ~]#awk 'BEGIN{n=1;max=0;nu=0}{for(n=1;n=max)max=a[$n]}{print max}{max=0}}' urfile
2
2
3
解释说明
使用数组将每个数字记录,然后将每个值与max变量比较,若比max大,则将内容赋予max;使用nu记录行号,每行执行最后将max置0