wc
DESCRIPTION
Print line, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. With no FILE, or when FILE is -,
read standard input.
Options -c -w and -l specify whether to print the count of one
or more of characters, words, or lines. If no option is given,
all three are printed.
If you want to use the output of wc in a calculation, redirect or pipe
the file[s] into the command, and store the output in a variable:
lines=`wc -l < FILE`
lines=`cat *.txt | wc -l`
Some versions of wc will put spaces before the output,
and this can cause problems. The spaces can be
removed by enclosing the result in an arithmetic expression:
lines=$(( `wc -l < FILE` ))
lines=$(( `cat *.txt | wc -l` ))
Or you can set the results into the positional parameters, which
has the advantage of removing any whitespace, as well as giving you
the word count and character count if you want them:
set -- `wc FILE`
lines=$1
words=$2
chars=$3
set -- `cat *.txt | wc`
lines=$1
words=$2
chars=$3
|