Shell-Script

如何使用shell命令計算文件中每個句子的單詞數?

  • July 10, 2015

我有這樣的文本文件:

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

所有文件只有四行

只有字數必須列印為輸出,就像這樣:

8
10
9
4

你可以這樣做:

awk '{print NF}' filename

由於您用 標記了您的問題wc,因此這裡有一個使用它的解決方案(儘管不是最佳的):

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

引用自:https://unix.stackexchange.com/questions/215076