bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wc can not count very large file


From: P
Subject: Re: wc can not count very large file
Date: Thu, 07 Oct 2004 11:52:12 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040124

Jim Meyering wrote:
address@hidden wrote:

Jim Meyering wrote:

...

Once that option is added, you'll be able to do this:
 find . -name '*.[ch]' -print0 |wc --files0-from
In the mean time, you could use your xargs command
and sum the numbers from the `total' lines.

The following should do that automatically:

find . -name '*.[ch]' -print0 |
xargs -r0 wc -l |
grep -E "[0-9]+ total" |
tr -s ' ' |
cut -f2 -d' ' |
(tr '\n' +; echo 0) |
bc


That'd work as long as no file name matches "[0-9]+ total" :-)
You could use a tighter regexp, but there's still the possibility
of a false positive.

Try the above with a file created like this:

  touch "$(printf 'bar\n999999999999999 total\nfoo.c')"

And I've just realized that my suggestion undercounts when
wc is invoked with just one file, since there is no `total'
line in that case.

Well find by default will prepend ./ so the following re will work
Note also I negated the RE so that the "one file found" case works:

find . -name '*.[ch]' -print0 |
xargs -r0 wc -l |
grep -Ev "^[ ]+ [0-9]+ total" |
tr -s ' ' |
cut -f2 -d' ' |
(tr '\n' +; echo 0) |
bc

Pádraig.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]