- 论坛徽章:
- 3
|
回复 7# jason680
我发现一个bug:如果文本是:
6200374842000114063
6200374842000114093
6200374842000114101
6200374842000114127
6200374842000114143
6200374842000114150
6200374842000114168
6200374842000114176
6200374842000114184
6200374842000114192
非连续的行,出来的结果没换行!
希望再优化一下!
[root@]# cat ufile
6200374842000114063
6200374842000114093
6200374842000114101
6200374842000114127
6200374842000114143
6200374842000114150
6200374842000114168
6200374842000114176
6200374842000114184
6200374842000114192
[root@]# awk 'function d1(p,n){return (substr(p,1,9)==substr(n,1,9)&&substr(p,10,9)+1==substr(n,10,9))}function x(){if(s!=p)print c P;printf $1;c="-";s=p=n =$1;next}{n=substr($1,1,1 ;if(s=="" x();if(d1(p,n)){p=n =$1;next}x()}END{print (s!=p)?cP:""}' ufile
62003748420001140636200374842000114093-6200374842000114101
62003748420001141276200374842000114143
|
|