boop
boop

Reputation: 57

Count number of words in many files with unix

I have a bunch of files named xaa, xab, xac,..., xtf. I need to return the count of words in each of these fies.

I currently have:

grep -o ' ' x* | wc -l 

but this just gives me 1's when there are several words...

(I posted something like this already... I am trying to explain in a clearer manner what I am having trouble with.)

Upvotes: 0

Views: 83

Answers (2)

falsetru
falsetru

Reputation: 369394

-l option of wc make it to print line count. To get word count, use -w option.

grep -o .. prints only the matched parts. Use cat instead:

cat x* | wc -w

UPDATE according to the comment:

wc -w x*

Upvotes: 1

William Pursell
William Pursell

Reputation: 212534

cat x* | wc -w

should do what you want

Upvotes: 0

Related Questions