Count the number of words in some subset of file and disregard others

Hi All,

I have some 6000 text files in a directory. My files are named like 1.txt, 2.txt 3.txt and so on until 6000.txt. I want to count the "number of words" in only first 3000 of them. Any suggestions?

I know

wc -w

can count the number of words in a text file. I am using Red Hat Linux.

Try this

#!/bin/ksh

for i in `seq 3000`
do
  wc -w $i.txt
done

regards,
Ahamed

1 Like

Could this help you? What is size of your file ?

i=1;while (( i <= 3000 )); do wc -w $i".txt"; i=`expr $i + 1`;done
1 Like

Well, the size is not fixed its variable and so are the number of words. :slight_smile: