【问题标题】:Finding the line, with leading blanks, starting with the great value寻找行,前导空白,从大价值开始
【发布时间】:2015-01-12 17:27:15
【问题描述】:

我正在使用 bash 命令对一些结果进行排序。我的file_of_counts基本上是这样的

 23 (some text),(1 2 3 4 1)
 95 (some text),(1 2 3 3 5)
  9 (some text),(1 2 3 5 5)
 10 (some text),(1 2 3 2 5)
 10 (some text),(1 2 3 4 4)
 45 (some text),(1 2 3 4 2)

我做到了这一点

cat myfile | grep some_term | uniq -c > file_of_counts

所以我找到了带有关键字“some_term”的行,然后找到了唯一的行,其中uniq -c 还给出了每个唯一行的计数,这基本上已经在上面的示例file_of_counts 中进行了描述。

如您所见,每一行都有一些前导空格。由于某种原因,我无法制作

cat file_of_counts | sort 

工作,或者更确切地说,它不会给我正确的答案。我必须在前导空白或其他东西上遗漏一些明显的东西。帮助表示赞赏。

【问题讨论】:

    标签: bash sorting unix grep uniq


    【解决方案1】:

    尝试添加-n开关:

    $ sort -rn file
    

    输出:

     95 (some text),(1 2 3 3 5)
     45 (some text),(1 2 3 4 2)
     23 (some text),(1 2 3 4 1)
     10 (some text),(1 2 3 4 4)
     10 (some text),(1 2 3 2 5)
      9 (some text),(1 2 3 5 5)
    

    来自man sort

        -n, --numeric-sort
               compare according to string numerical value
    

    【讨论】:

      猜你喜欢
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 2016-06-28
      • 1970-01-01
      相关资源
      最近更新 更多