- 论坛徽章:
- 32
|
- [root@localhost ~]# sort --version
- sort (coreutils) 5.2.1
- Written by Mike Haertel and Paul Eggert.
- Copyright (C) 2004 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- [root@localhost ~]# sort -V i
- sort: invalid option -- V
- Try `sort --help' for more information.
- [root@localhost ~]# sed -r 's/^([a-z]+)([0-9]+)(.*)$/\1 \2\3/' i | sort -n -k2|sed -r 's/([a-z]+) ([0-9]+)(.*)$/\1\2\3/'
- eth90 QEfqcBHD oxYT
- eth104 smwnzrnX WLsz
- eth178 RuQdYFdG JsWE
- eth191 BYPSdivD NQFL
- eth195 yUJEkrom KvBL
- eth232 GVpXbDGT XuwP
- eth233 vrMllyud Onbi
- eth237 GlBlKJAn LXPI
- eth239 tBJmMpcq clXg
- eth255 dunTcnWO VrXT
- [root@localhost ~]# awk '{a[substr($1,4)]=$0}END{n=asorti(a,b,"@ind_num_asc");for(i=1;i<=n;i++)print a[b]}' i
- awk: cmd. line:1: fatal: 3 is invalid as number of arguments for asorti
- [root@localhost ~]# awk '{a[substr($1,4)]=$0}END{n=asorti(a,b,"@ind_num_asc");for(i=1;i<=n;i++)print a[b[i]]}' i
- awk: cmd. line:1: fatal: 3 is invalid as number of arguments for asorti
- [root@localhost ~]#
复制代码 第一个用不了,不知道是不是版本问题;第二个可以,但是我觉得太麻烦了,用到了管道,还用到了sort,还不如直接用sort呢;第三个有问题,请你再仔细检查一下。
下面是我的方法:- [root@localhost ~]# sort -n -k1.4 i
- eth90 QEfqcBHD oxYT
- eth104 smwnzrnX WLsz
- eth178 RuQdYFdG JsWE
- eth191 BYPSdivD NQFL
- eth195 yUJEkrom KvBL
- eth232 GVpXbDGT XuwP
- eth233 vrMllyud Onbi
- eth237 GlBlKJAn LXPI
- eth239 tBJmMpcq clXg
- eth255 dunTcnWO VrXT
- [root@localhost ~]#
复制代码 |
|