[Top][All Lists]

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

Re: wc

From: Bob Proulx
Subject: Re: wc
Date: Tue, 16 Jan 2001 00:07:59 -0700 (MST)

> when I run wc on many files (using find . ... | xargs wc), it prints
> out several "total" columns (one for each subdirectory).  However,
> this is not documented in the info or man page. Is this a bug? If
> not, the absence of documentation or a switch to disable that (and
> get only one total) seems to be one to me.

I believe you are misunderstanding the way 'find | xargs' works.  I
believe wc is working correctly.  Try your find | xargs command but
instead of wc use 'echo wc'.  You should see that you are handing many
files and directories to it all at one time.  But you are also running
the wc many, many times.  Each time it runs you are getting a total

If your number of files is small you could use:

  wc `find . -print`

But that will run out of memory space if you have many files, which is
presumably why you were using find|xargs in the first place.  xargs
works great for programs that have not state but just modify
something, such as chown and chmod.  But wc has state.  It counts up
and totals.  Each time it runs it prints a new total.

Off the top of my head I can't see a way to get a total from wc for a
large set of files too large to pass on the command line.  But you can
sum them up after the fact.

  find . -type f -print | xargs wc \
  | awk '{l+=$1;w+=$2;b+=$3}END{printf("%d %d %d\n",l,w,b);}'

That is just off of the top of my head.  You may want quite a
different solution than what I am proposing here.  Your mileage may
vary.  Etc.


reply via email to

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