我想获取单词长度的频率计数(test.txt是单词列表)。下面的代码应计算不同长度的单词数,然后将结果相加;重复直到达到文件中的单词总数。问题在于cur
变量的分配,该变量应存储管道操作(grep | wc -w
)的输出。一旦达到该语句,cur:command not found
就会在终端上显示。我正在使用Cygwin。我该如何运作?
#!/bin/bash
a=($(wc test.txt))
filename=$dir/freq.txt
touch $filename
words=${a[1]} #words variable stores the total number of words in test.txt file
total=0
count=1 #first check the number of words of length 1
while [ "$total" -ne "$words" ] #terminate once total equals words
do
cur = $(grep -o -w "\w\{$count\}" male-first.txt | wc -w) #number of words of length count
echo "$count: $cur"
let count++ #increment count
let total=total+cur #add number of words of length count to total
done
echo "Done"
不允许在作业周围留空格:
cur=$(grep...