user3335040
user3335040

Reputation: 669

How do I get the number of lines for specific files in a large directory?

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.

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

Upvotes: 2

Views: 102

Answers (2)

Edouard Thiel
Edouard Thiel

Reputation: 6208

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

Upvotes: 1

Slava Semushin
Slava Semushin

Reputation: 15194

Try the following:

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

Upvotes: 2

Related Questions