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 10:08:35 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040124

Jim Meyering wrote:
pwu <address@hidden> wrote:

I have tried to calculate how many lines in our project.  In one
directory it give me the value is 160k, but the total number for all
directories are only 50k.
my command is like this:
find . -name '*.[ch]' |xargs wc
The newlines are only 50K. I have about 20 directories, each has 100k
to 300k lines. I guess it is because wc use int not long to calculate
the lines and bytes


Beware of using xargs with wc like that.

If you have too many files to fit in one command-line buffer,
xargs will invoke wc more than once, and you'll end up with two
or more `total' lines.  You're probably seeing only the last one.

coreutils has a TODO item that will eventually address this:

  wc: add an option, --files0-from [as for du] to make it read
    NUL-delimited file name arguments from a file.

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

Pádraig.




reply via email to

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