【问题标题】:How count the number of lines of a file group?如何计算文件组的行数?
【发布时间】:2011-12-19 17:39:14
【问题描述】:

我想计算在指定月份中包含所有日志文件的行数。到目前为止,我使用以下命令获取这些文件。

ls localhost_access_log.[0-9][0-9]-11-11*

此文件名的示例是 localhost_access_log.10-10-11.log

我试过用

ls localhost_access_log.[0-9][0-9]-11-11* | wc -l 

这个选项给我的是ls过滤的文件数,不是我想要的。我想要拥有这些文件的所有行的总和。谢谢

【问题讨论】:

  • 我更新了答案。你真的不需要wc

标签: regex linux ls wc


【解决方案1】:

这将为您提供所有文件中的总行数 -

wc -l localhost_access_log.[0-9][0-9]-11-11* | awk 'END{print $1}'

更好 -

awk 'END{print NR}' localhost_access_log.[0-9][0-9]-11-11*

【讨论】:

    【解决方案2】:

    试试:

    wc -l localhost_access_log.[0-9][0-9]-11-11* 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 1970-01-01
      • 2012-09-26
      • 2011-10-14
      • 2011-03-05
      • 1970-01-01
      相关资源
      最近更新 更多