I don't know if you're still looking for answers to this, but I thought I'd have a bash anyway (no pun intended :
).
To count the f's in myfile.txt
Code:
sed -e 's/f/f\
/g' myfile.txt |grep --count f
grep counts only lines, so the sed replaces all f's with f followed by newline (the new line in that sequence is quite deliberate). I guess if you research a bit, you could probably come up with something less clumsy 
Similarly:
Code:
sed -e 's/\bmilk\b/\0\
/g' myfile.txt |grep --count "\bmilk\b"
A sentence count might be (probably some flaws in my thinking here but what the hell)
Code:
sed -e 's/[\.\?\!]+/\0\
/g' myfile.txt |grep --count "[\.\?\!]"
To assign the output from a command such as those above to a variable in your script, you need to surround the sequence with the backtick (`) character.
To add an extra line you could use:
Code:
cat >>myfile.txt
To replace a word, modify that sed above (the one that replaces milk with milk newline).
As for your menu function, I can only assume bash doesn't like recursion much. One way around it would be:
Code:
function menu
{
while :
do
<your menu code>
done
}
This will create a never ending loop. Of course you could add a quit option and put it in as a condition to the while loop.
Edit: corrected half baked sentence count (a bit)
Bookmarks