The shell is sh.
I have been using a for loop:
for F in *.txt
do
echo `wc -w $F`
done
This has been returning the number of words and the name of the file. I don't understand why it keeps returning the name of the file; it looks like it should only return the number of words in the file.
This is the default behavior of wc, it shows the filename after the count.
If you just want the count, pass the filename via STDIN:
wc -w <filename
Also, without iterating over the files using for, you could just use globbing for getting the filenames at once, wc takes multiple arguments so there would not be a problem:
wc -w *.txt
In this case, to get rid of the filenames, use some text-processing:
wc -w *.txt | awk '{print $1}'
This should be faster than the fora approach you have already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With