Last active
December 24, 2017 00:41
-
-
Save paddy74/f05592e50261c79620a7ddff57279600 to your computer and use it in GitHub Desktop.
Count the number of words, sentences, and average number of words per sentence in a text file. Created for CS252 at Old Dominion University.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
for f in "$@" | |
do | |
w=`cat "$f" | sed "s/ */\\n/g" | sed "s/[^a-zA-Z0-9]//g" | sed "s/[0-9]*//g" | sed "/^$/d" | wc -w` | |
s=`cat "$f" | tr -d " \t\n\r" | sed "s/\./\\n/g" | sed "s/\?/\\n/g" | sed "s/\!/\\n/g" | wc -l` | |
z=$(expr "$w" / "$s") | |
echo $f: | |
echo " "$w words | |
echo " "$s sentences | |
echo " "The average sentence is $z words long. | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment