请教shell排序问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
215317196
帖子: 49
注册时间: 2008-06-10 10:52
联系:

请教shell排序问题

#1

帖子 215317196 » 2011-08-25 17:38

arp -n 输出很多IP,如下:

代码: 全选

192.168.0.178            ether   00:1E:6F:00:25:24   C                     eth0
192.168.0.179            ether   00:1E:6E:00:15:82   C                     eth0
192.168.0.53             ether   6C:F0:49:88:3E:CA   C                     eth0
192.168.0.47             ether   00:27:19:9C:68:34   C                     eth0
192.168.2.184            ether   00:1E:6E:00:58:39   C                     eth0
192.168.1.1            ether   00:0A:EB:09:8B:F4   C                     eth0
192.168.1.111            ether   1C:6F:65:9C:B4:C6   C                     eth0
192.168.3.183            ether   00:1E:6E:00:58:2B   C                     eth0
192.168.3.2            ether   00:1E:6E:00:58:2F   C                     eth0
192.168.2.183            ether   00:1E:6E:00:58:2B   C                     eth0
192.168.3.13            ether   00:1E:6E:00:5F:2B   C                     eth0

我想要按IP排序,怎么做啊。!!!
fnan
帖子: 919
注册时间: 2009-07-01 22:04

Re: 请教shell排序问题

#2

帖子 fnan » 2011-08-25 18:23

直接sort就是了。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
1qa2ws3ed
帖子: 159
注册时间: 2011-06-29 19:18
系统: Archlinux

Re: 请教shell排序问题

#3

帖子 1qa2ws3ed » 2011-08-25 20:21

代码: 全选

sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 arp-output-file
Ubuntu Linux, Linux for human beings.
215317196
帖子: 49
注册时间: 2008-06-10 10:52
联系:

Re: 请教shell排序问题

#4

帖子 215317196 » 2011-08-26 12:46

以经解决了,谢谢!采纳3楼!!

代码: 全选

sort -n -u -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
回复