Use find, wc, and sed to count lines

后端 未结 8 1513
攒了一身酷
攒了一身酷 2020-12-25 12:17

I was trying to use sed to count all the lines based on a particular extension.

find -name \'*.m\' -exec wc -l {} \\; | sed ...

I was tryi

8条回答
  •  天涯浪人
    2020-12-25 12:43

    For big directories we should use:

    find . -type f -name '*.m' -exec sed -n '$=' '{}' + 2>/dev/null | awk '{ total+=$1 }END{print total}' 
    
    # alternative using awk twice
    find . -type f -name '*.m' -exec awk 'END {print NR}' '{}' + 2>/dev/null | awk '{ total+=$1 }END{print total}' 
    

提交回复
热议问题