![Linux 版本排序;字母优先](https://linux22.com/image/1571877/Linux%20%E7%89%88%E6%9C%AC%E6%8E%92%E5%BA%8F%EF%BC%9B%E5%AD%97%E6%AF%8D%E4%BC%98%E5%85%88.png)
GNUsort -V
非常适合对 IP 地址进行排序。不幸的是,它会将所有以字母(而不是数字)开头的行放在最底下。有办法解决吗?
注意:
• 192.168.0.103 缺失,因为它是本地主机。
• MAC/HW 地址已更改。
• 猫
user@host:~$ cat /proc/net/arp
IP address HW type Flags HW address Mask Device
192.168.0.106 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.1 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.101 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.104 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.110 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.108 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.107 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.102 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.105 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.100 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.109 0x1 0x2 00:00:00:00:00:00 * wlan0
• 排序 -V
user@host:~$ sort -V /proc/net/arp
192.168.0.1 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.100 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.101 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.102 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.104 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.105 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.106 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.107 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.108 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.109 0x1 0x2 00:00:00:00:00:00 * wlan0
192.168.0.110 0x1 0x2 00:00:00:00:00:00 * wlan0
IP address HW type Flags HW address Mask Device
答案1
这里有一种将标题保持在顶部的技术:重定向文件,并从流中获取第一行,然后对其余行进行排序。
{ IFS= read -r header; echo "$header"; sort -V; } < /proc/net/arp