如何获取大目录中特定文件的行数?

时间:2022-03-02 19:46:05

I have the command "find . -name '*.dmp' | xargs wc -l" to get the lines from all the dmp files in a directory. The dump files naming convention is "dump-10181.dmp" with the number being a unique incremental number.

我有“查找”命令。- name”*。dmp' | xargs wc -l"从目录中的所有dmp文件中获取行。转储文件命名约定是“dump-10181”。dmp"的数字是唯一的增量数字。

How do I get the number of lines for only files with the number 50 - 678?

我怎样才能得到只有数字50 - 678的文件的行数?

2 个解决方案

#1


2  

Try the following:

试试以下:

seq 50 678 | xargs -I'{}' cat dump{} | wc -l

#2


1  

Longer than other solutions but more general:

比其他解决方案更长但更普遍:

for f in *.dmp ; do \
    n=${f##*-}; n=${n%.dmp}; \
    [[ "$n" = "" || "$n" = *[^0-9]* ]] && continue ;\
    n=$((10#$n)) ; ((n >= 50 && n <= 678)) && cat "./$f" ;\
done | wc -l

#1


2  

Try the following:

试试以下:

seq 50 678 | xargs -I'{}' cat dump{} | wc -l

#2


1  

Longer than other solutions but more general:

比其他解决方案更长但更普遍:

for f in *.dmp ; do \
    n=${f##*-}; n=${n%.dmp}; \
    [[ "$n" = "" || "$n" = *[^0-9]* ]] && continue ;\
    n=$((10#$n)) ; ((n >= 50 && n <= 678)) && cat "./$f" ;\
done | wc -l