I know how to count the number of words.
How to count the number of characters in the marked (selected) region?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
shell-command-on-region (bound to
M-|) passes the region to the standard input of any shell command you want. The output is sent to the echo area if it is short enough or to a buffer whose name is stored in the variable
shell-command-buffer-name (whose value is
*Shell Command Output* by default) - or you can call the command with a prefix argument to replace the region by the output of the command.
Since you can use
wc from the shell to count (lines, words, characters), you can do that from emacs by selecting the region and then
M-| wc. Or to uppercase the region:
C-u M-| tr a-z A-Z, or to get an uppercase copy of the region in the output buffer:
M-| tr a-z A-Z. You can probably easily come up with a dozen more.
There are emacs equivalents to those and many more and it is often better to use them, but I find
M-| to be a useful tool in my toolbox. It lets me use shell commands I know well to do some things that might require some time and effort to research, were I to use native tools.