|
|
|
|
|
by contras1970
2654 days ago
|
|
i wonder why he has the "wrapper over wc" which does just what wc does? #!/bin/sh
total=0
for FILE in `find . -type f -name "*.txt"`
do
wc -w $FILE
words=`wc -w < $FILE | tr -d ' '`
total=$(($total + $words))
done
printf "%'d" $total
echo " words"
all this achieves is wc -w $(find . type f -name "*.txt") | sed '$s/total/words/'
and frankly, i'm not sure the total->words substitution is worth the trouble.then there's the inefficiency of running wc twice per file. while this is not exactly bitcoin-level disaster, it rubs me the wrong way... wc -w $(find . type f -name "*.txt") |
awk -v t=0 '
{ print; t += $1 }
END { print t, "words"; }
'
personally i'd just do this (in zsh): wc -w **/*.txt(.D)
the (.D) is two "glob qualifiers": the . (dot) limits the result to plain files, the D turns GLOB_DOTS on for the pattern. |
|