使用 Linux 命令的词长频率计数
Word length frequency count with Linux commannds
我想获取单词长度的频率计数(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"
不允许 space 赋值:
cur=$(grep...
我想获取单词长度的频率计数(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"
不允许 space 赋值:
cur=$(grep...