昨天要排序一个文件:
Ethernet0/1
Ethernet0/10
Ethernet0/11
Ethernet0/12
Ethernet0/13
Ethernet0/14
Ethernet0/15
Ethernet0/16
Ethernet0/17
Ethernet0/18
Ethernet0/19
Ethernet0/2
Ethernet0/20
Ethernet0/21
Ethernet0/22
Ethernet0/23
Ethernet0/24
Ethernet0/25
Ethernet0/26
Ethernet0/27
Ethernet0/28
Ethernet0/29
Ethernet0/3
Ethernet0/30
Ethernet0/31
Ethernet0/32
Ethernet0/33
Ethernet0/34
Ethernet0/35
Ethernet0/36
Ethernet0/37
Ethernet0/38
Ethernet0/39
Ethernet0/4
Ethernet0/40
Ethernet0/41
Ethernet0/42
Ethernet0/43
Ethernet0/44
Ethernet0/45
Ethernet0/46
Ethernet0/47
Ethernet0/48
Ethernet0/5
Ethernet0/6
Ethernet0/7
Ethernet0/8
Ethernet0/9
GigabitEthernet1/1
GigabitEthernet2/1
后面的数字要按照数字的顺序排序.我知道-n参数可以实现,但是试验半天没有搞定.
发一个帖子:http://www.itpub.net/thread-1593746-1-1.html
终于知道如何实现,原来n可以放在参数k的后面.
sort -t'/' -k1,1 -k2,2n test.txt
Ethernet0/1
Ethernet0/2
Ethernet0/3
Ethernet0/4
....
Ethernet0/45
Ethernet0/46
Ethernet0/47
Ethernet0/48
GigabitEthernet1/1
GigabitEthernet2/1
感谢跟帖帮助的itpub 朋友.