- 论坛徽章:
- 1
|
改了下可以了[code]
sed 's/[a-z ]*/& /' 1.txt|sort -k1,1 -k2,2 -k3,3n|awk '{
a[NR]=$1FS$2$3
}
END{
for (i=1;i<=NR;i++) {
split(a[i],b,FS)
if (!c[b[1]])
c[b[1]]=b[2]","
else {
count=split(c[b[1]],d,",")
match(d[count-1],/a-z+/)
old1=substr(d[count-1],RSTART,RLENGTH)
match(b[2],/a-z+/)
new1=substr(b[2],RSTART,RLENGTH)
match(d[count-1],/[0-9]+$/)
old2=substr(d[count-1],RSTART,RLENGTH)
match(b[2],/[0-9]+/)
new2=substr(b[2],RSTART,RLENGTH)
if (old1==new1 && (old2+1)==new2||old2==new2) {
c[b[1]]=substr(c[b[1]],1,length(c[b[1]])-1)
sub(/-[0-9]+$/,"",c[b[1]])
c[b[1]]=c[b[1]]"-"new2","
}
else
c[b[1]]=c[b[1]]""b[2]","
}
}
for (i in c)
print i":"substr(c[i],1,length(c[i])-1)
}'
[/code] |
|