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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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}'