I want to get the frequency count for word lengths (test.txt is a list of words). The code below should calculate the number of words of different lengths then add the result; repeat till it reaches the total number of words in a file. The problem is with the assignment of cur
variable, which should store the output of pipe operation (grep | wc -w
). Once this statement is reached cur:command not found
appears on a terminal. I am using Cygwin. How can I make it work?
#!/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"
Don't allow space around assignments:
cur=$(grep...