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
There's also awk:
$ echo -e "hello world\nbye all" | awk -Fl '{c += NF - 1} END {print c}'
5
Change -Fl
to -F
.
This works by setting the field delimiter to the character specified by -F
, then accumulating the number of fields on each line - 1 (because if there's one delimiter, there are two fields - but we should only count 1).