Linux排序组合-V和-f

时间:2017-09-15 02:30:03

标签: linux bash sorting gnu-coreutils

我想结合排序-V和-f。有办法吗?

这是一个简单的例子。我想对此列表进行排序。

> cat testme

a1
a2
a11
a12
a3
A8
B8
b1
b11

默认排序首先是大写,小写第二,加上a11在a2

之前
> cat testme | sort

A8
B8
a1
a11
a12
a2
a3
b1
b11

我使用的-V很棒,a2在a11之前,但它仍然是大写然后是小写

> cat testme | sort -V

A8
B8
a1
a2
a3
a11
a12
b1
b11

我可以排序-f修复案例,但a11仍然在a2

之前
>cat testme | sort -f

a1
a11
a12
a2
a3
A8
b1
b11
B8

我尝试将它们组合起来,但是-V胜利和-f失败。

>cat testme | sort -f -V

A8
B8
a1
a2
a3
a11
a12
b1
b11

是否可以选择合并这些?

所需的输出是:

a1
a2
a3
A8
a11
a12
b1
B8
b11

正在使用的版本:

[03:11:09] sa-hq1:~ # sort --version
sort (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

2 个答案:

答案 0 :(得分:0)

在我的Fedora 25上,它运行正常。

    [root@localhost ~]# sort --version
    sort (GNU coreutils) 8.25
    Copyright (C) 2016 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Mike Haertel and Paul Eggert.
    [root@localhost ~]# sort -Vf testme
    a1
    a2
    a3
    A8
    a11
    a12
    b1
    B8
    b11

[root@localhost ~]#

答案 1 :(得分:0)

无需cat文件到sort命令。它可以从stdinargument list

中读取文件
sort -Vf file

sort -Vf < file  

测试:

~ > sort -Vf < file

a1
a2
a3
A8
a11
a12
b1
B8
b11
~ > sort -Vf file

a1
a2
a3
A8
a11
a12
b1
B8
b11
~ >