免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: SickWorm

关于ethers文件里的排序 [复制链接]

论坛徽章:
0
发表于 2003-02-28 18:58 |显示全部楼层

关于ethers文件里的排序

sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4 ethers
sort -n -t. +0 -4 ethers

有区别吗?

论坛徽章:
0
发表于 2003-02-28 19:32 |显示全部楼层

关于ethers文件里的排序

原帖由 "didikei" 发表:
sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4 ethers
sort -n -t. +0 -4 ethers

有区别吗?



有区别的。

第一种是指,先按第一段比较,如果第一段相同,对第一段相同的还需再比较第二段,依此类推……
第二种指的是,从一到四段作为一个整体来比较,因为当中含有点,不是正式的数字,所有比较的结果是错误的。

看一下具体的例子:

# sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4 ip.txt
72.16.1.3 00:50:AF:00:C8:E6
172.16.1.3 00:50:AF:00:C8:E6
172.16.1.3 00:50:AF:00:C8:E6
172.16.1.32 00:50:BF:00:C8:E6
172.26.1.221 00:50:BF:00:C8:E9
172.126.1.221 00:50:BF:00:C8:E9
272.16.3.3 00:50:AF:00:C8:E6

# sort -n -t. +0 -4 ip.txt
72.16.1.3 00:50:AF:00:C8:E6
172.126.1.221 00:50:BF:00:C8:E9
172.16.1.3 00:50:AF:00:C8:E6
172.16.1.3 00:50:AF:00:C8:E6
172.16.1.32 00:50:BF:00:C8:E6
172.26.1.221 00:50:BF:00:C8:E9
272.16.3.3 00:50:AF:00:C8:E6

你看,实际上只排了第一段,第二段开始,不再是数字大小排列了,最多就是按string顺序排列了。

论坛徽章:
0
发表于 2003-02-28 20:02 |显示全部楼层

关于ethers文件里的排序

从一到四段作为一个整体深刻

论坛徽章:
0
发表于 2003-03-03 09:31 |显示全部楼层

关于ethers文件里的排序

中间的数字的正负有什么含义呀?

论坛徽章:
0
发表于 2003-03-04 11:38 |显示全部楼层

关于ethers文件里的排序

up!!

论坛徽章:
0
发表于 2003-03-04 11:47 |显示全部楼层

关于ethers文件里的排序

原帖由 "红袖添香" 发表:
...

sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4  ethers



+0 -1 是不是说域1-2组成排序的主关键字
+2-3  ............域3-4。。。。。次关键字
。。。。。。。。。。。。。。。。。。。。

红袖姐,不知道我说的对不对啊?!

论坛徽章:
0
发表于 2003-03-04 16:35 |显示全部楼层

关于ethers文件里的排序

原帖由 "nmgzw" 发表:



+0 -1 是不是说域1-2组成排序的主关键字
+2-3  ............域3-4。。。。。次关键字
。。。。。。。。。。。。。。。。。。。。

红袖姐,不知道我说的对不对啊?!


差不多了,弟弟。

+0 -1 表示 域 1
+1 -2 表示 域 2
+2 -3 表示 域 3
+3 -4 表示 域 4

man sort

...
     [+pos1 [-pos2]]
           (obsolete). Provide functionality  equivalent  to  the
           -kkeydef option.

           pos1 and pos2 each have the form m.n  optionally  fol-
           lowed  by one or more of the flags bdfiMnr. A starting
           position specified by +m.n is interpreted to mean  the
           n+1st character in the m+1st field. A missing .n means
           .0, indicating the first character of the m+1st field.
           If the b flag is in effect n is counted from the first
           non-blank in the m+1st  field;  +m.0b  refers  to  the
           first non-blank character in the m+1st field.

           A last position specified by -m.n  is  interpreted  to
           mean  the  nth  character (including separators) after
           the last character of the  mth  field.  A  missing  .n
           means  .0,  indicating  the  last character of the mth
           field. If the b flag is in effect n  is  counted  from
           the  last  leading  blank  in  the  m+1st field; -m.1b
           refers to the first non-blank in the m+1st field.

           The fully specified +pos1 -pos2 form with type  modif-
           iers T and U:

           +w.xT -y.zU
...

论坛徽章:
0
发表于 2003-03-04 18:14 |显示全部楼层

关于ethers文件里的排序

哦,这样啊,原来我还纳闷呢!10.1.25.36只有4 个点,可按我的想法应该是10.1.25.36.45才对,现在我才明白为什么!
谢谢红袖姐!!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2003-03-05 03:47 |显示全部楼层

关于ethers文件里的排序

啊就好!

论坛徽章:
0
发表于 2003-03-05 08:36 |显示全部楼层

关于ethers文件里的排序

大人说话,不许小孩子参和!·
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP