- 论坛徽章:
- 5
|
本帖最后由 blackold 于 2010-04-01 23:20 编辑
try:
- awk '{if(a[$1]+a[$2]==0)a[$1]=a[$2]=++n;else if(a[$1]!=a[$2]){if(a[$1]*a[$2]==0)a[$1]=a[$2]=a[$1]+a[$2];else{min=(a[$1]<a[$2])?a[$1]:a[$2];max=(a[$1]<a[$2])?a[$2]:a[$1];for(i in a)if(a[i]==max)a[i]=min}}}END{for(i in a)print a[i],i}' urfile|sort -n
复制代码 scr.awk
- {
- if(a[$1]+a[$2]==0)
- a[$1]=a[$2]=++n
- else if(a[$1]!=a[$2])
- {
- if(a[$1]*a[$2]==0)
- a[$1]=a[$2]=a[$1]+a[$2]
- else
- {
- min=(a[$1]<a[$2])?a[$1]:a[$2]
- max=(a[$1]<a[$2])?a[$2]:a[$1]
- for(i in a) if(a[i]==max)a[i]=min
- }
- }
- }
- END {
- for(i in a) print a[i],i
- }
复制代码- awk -f scr.awk urfile|sort -n
复制代码 |
|