How to pipe content in Emacs' buffer to external program, and print the result? How to pipe content in Emacs' buffer to external program, and print the result? bash bash

How to pipe content in Emacs' buffer to external program, and print the result?


Use shell-command-on-region which is bound to M-|

e.g.:
M-| sort | uniq -c RET

With a prefix argument, the region is replaced by the output of the shell command (which effectively adds all shell commands to Emacs' editing toolkit; very useful when you know how to do something outside of Emacs, but don't know an equivalent native function).

C-uM-| sort | uniq -c RET