I have a few text files and I\'d like to count how many times a letter appears in each?
Specifically, I\'d like to use the UNIX shell to do this, in the form of: cat fil
grep char -o filename | wc -l
try it with
grep [PATTERN] -o [FILE] | wc -l
and please do not use cat if not needed.
echo "a/b/c/d/e/f/g" | awk -F"/" '{print NF}'
this will give the number of occurrence of character "/"
In this case, i'am counting the character "|":
expr `wc -c < filename` \- `tr -d \| < filename | wc -c`
You can try easily:
grep -c 'YOUR LETTER' YOUR FILE
Another alternative:
tr -d -C X <infile | wc -c
where X is the character or string of characters you want to count and infile is the input file.