Search code examples
regexlinuxlswc

How count the number of lines of a file group?


I want to count the number of lines that have all the log files in a specified month. So far I get those files with the following command.

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

An example of this file name is localhost_access_log.10-10-11.log

I tried to use

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

this option gives me is the number of files filtered by ls, not what I want. I want the sum of all the lines that have these files. Thanks


Solution

  • This will give you the total number of lines in all files -

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

    Even better -

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