Posts Tagged ‘unique words count’

Iam back with another shell script written for my sis as part of her assignment. This time what i wanted to do is to count the unique words in a file and to print it in alphabetical order. For that i iterated through the words in the given file using for loop, filtered out the unique words using sort -u and counted it using wc -l.

echo Enter the filename
read fn

for WORD in $(cat $fn)
	echo "$WORD"
done | sort -u | wc -l	

 for WORD in $(cat $fn)
  echo "$WORD "
 done | sort -u

Hope this will help someone to do his/her assignment 😀

Read Full Post »

%d bloggers like this: