【问题标题】:Sort duplicates in multiple files对多个文件中的重复项进行排序
【发布时间】:2019-04-18 00:32:50
【问题描述】:

我对编程很陌生,我才刚刚开始,所以请不要以为我只是想吃勺子。

我正在尝试完成一项任务,但我被卡住了。 这个想法是在许多文件中对重复的字符串进行排序。

它们都在一个文件夹中。 带有 1.txt、2.txt...n。 txt

1.txt:

hello
hi
world

2。 txt

hi
there
hello

它们都包含不同的字符串。 我想对它们进行排序并得到结果:

2 hello
1 world

等等

我通过一些搜索尝试了这个,但没有运气。

sort file1.txt | uniq -c

这主要是为一个文件做的,我想一次为所有文件做。

非常感谢你的帮助!

【问题讨论】:

    标签: sorting unix duplicates uniq


    【解决方案1】:

    我会 cat 两个文件,然后对值进行排序和计数:

    $ cat file1.txt file2.txt | sort | uniq -c  
    

    【讨论】:

      猜你喜欢
      • 2016-11-05
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 2011-12-03
      • 2019-11-13
      • 2016-12-23
      • 1970-01-01
      • 2020-09-19
      相关资源
      最近更新 更多