在此处使用 shell 脚本,尝试在不使用 wc 命令的情况下计算文件中的单词/字符/行数。我可以将文件分成几行并轻松计算那些,但我在这里努力获取单词和字符。
#define word_count function
count_stuff(){
c=0
w=0
l=0
local f="$1"
while read Line
do
l=`expr $line + 1`
# now that I have a line I want to break it into words and characters???
done < "$f"
echo "Number characters: $chars"
echo "Number words: $words"
echo "Number lines: $line"
}