count how many times every word occurs in some text file

4 views
Skip to first unread message

Copper Hill

unread,
May 21, 2009, 5:44:31 AM5/21/09
to worldhunter
words() {
if [ $# -lt 1 ]; then
echo "Please follow the name of an text file."
else
for i in `grep -o "\b[A-z][A-z][A-z]\+\b" "$1" |sed 's/.*/\L&/
g'|sort|awk '{if ($0!=line) print;line=$0}'`;do n=`grep -io $i "$1" |
wc
-l` && echo "$n,$i"; done|sort
fi
}


#find all the words in the text file
grep -o "\b[A-z][A-z][A-z]\+\b" "$1"
#make all the words lowercase
sed 's/.*/\L&/g'
#remove all the duplicate words
awk '{if ($0!=line) print;line=$0}'
Reply all
Reply to author
Forward
0 new messages