【问题标题】:Sorting files based on content using command line使用命令行根据内容对文件进行排序
【发布时间】:2012-03-14 19:27:37
【问题描述】:

我在一个文件夹中有一个文件数据库。我希望将包含*C: 的文件分类到一个文件夹中,将包含*c: 的文件分类到另一个文件夹中。这如何实现?**

我可以使用*.krn 访问每个文件。

【问题讨论】:

  • 那些包含both *C: *c: 的文件呢?还是都不
  • 他们不会。但在那种情况下,它们可以保持不变,或者最简单的方法。我认为如果有一个命令可以提取“*C:”,那么我可以在数据库上再次为“*c:”执行相同的命令

标签: linux sorting command-line grep


【解决方案1】:
$ grep --help | grep with-matches
-l, --files-with-matches  print only names of FILEs containing matches

现在的情况取决于有多少文件以及您对文件名称的偏执程度。从最简单的开始

mv $(grep -l pattern files) target

到最强大的

grep -l -Z pattern files | xargs -0 mv -t target-directory --

【讨论】:

    猜你喜欢
    • 2013-06-07
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多