2

I have text files like this:

Mr.P.K.Baneerjee has visited the site today at 4.30pm
The permit tag has been set in the ds busbar
Opearation has been performed in presence of control engineer
Opeation was successfully completed

All files have only four lines

Only the count of words must be printed as an output, just like this:

8
10
9
4
5

You can do it with:

awk '{print NF}' filename

2

Since you tagged your question with wc, here's a solution (albeit non-optimal) that uses it:

while read -r line; do echo $line | wc -w; done < filename.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.