Re: 在 shell 中能对 ip 地址排序吗?
$ cat 1.txt | sort -t . -n -k 1,4
1.1.1.1
192.168.2.234
192.168.2.237
192.168.2.246
192.168.2.247
192.168.2.28
192.168.2.50
192.168.2.51
192.168.4.192
192.168.4.51
255.1.1.1
2009/5/12 Dongsheng Song <dongsheng.song@gmail.com>:
> 你们没有考虑第三个,第二个,甚至是第一个字段呢:
>
> $ sort -n -t \. -k4 ip.txt
> 192.168.2.28
> 192.168.2.50
> 192.168.2.51
> 192.168.4.51
> 192.168.4.192
> 192.168.2.234
> 192.168.2.237
> 192.168.2.246
> 192.168.2.247
>
> 2009/5/12 Alyex Ye <alyex.ye@gmail.com>:
>> 用这个
>> sort -n -t \. -k4 ip.txt
>>
>> 在man sort中:
>> -k, --key=POS1[,POS2]
>> start a key at POS1, end it at POS2 (origin 1)
>>
>
--
Best Regards
LI Daobing
Reply to: