- 论坛徽章:
- 16
|
回复 9# dahaoshanhe
localhost:~ test$ sort -k1n <<<"63 63
74 74
82 82
95 95
96 96
99 99
97 97
98 98
100 100
114 114
123 123
"
63 63
74 74
82 82
95 95
96 96
97 97
98 98
99 99
100 100
114 114
123 123
localhost:~ test$ awk '
{
t1=$1
t2=$2
if (NR==1) { min=t1; max=t2; next }
if (t1<=max+1){ max=t2>max?t2:max}
else { print min,max; min=t1; max=t2 }
}
END{
print min,max}' <<<"63 63
> 74 74
> 82 82
> 95 95
> 96 96
> 97 97
> 98 98
> 99 99
> 100 100
> 114 114
> 123 123"
63 63
74 74
82 82
95 100
114 114
123 123
localhost:~ test$
|
|