【问题标题】:Find compressed files and output line查找压缩文件和输出行
【发布时间】:2013-11-22 08:17:51
【问题描述】:

我想输出几个压缩文件的特定行。由于我的研究,我认为我必须提取文件,然后 grep 我的字符串。例如。 gunzip -c 只是输出到STDOUT 我可以进一步处理。

我试过了:

find path/to/files -name archive.gz | xargs gunzip -c | awk 'NR==100{print}'

它只输出一个字符串(来自第二个文件的那个)。如果没有xargs,我会收到错误消息:gzip: stdin: not in gzip format

如果确实有 grep、sed、awk、perl 或任何其他标准 bash 工具的选项,我会很高兴获悉。

【问题讨论】:

    标签: bash compression


    【解决方案1】:

    您需要-exec 选项才能发出shell 命令:

    find path/to/files -name archive.gz -exec sh -c "gzip -dc {} | awk 'NR==100'" \;
    

    这将为find 命令生成的每个输出执行命令。

    【讨论】:

      猜你喜欢
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 2010-12-14
      • 2010-09-05
      相关资源
      最近更新 更多