You can use M-| (shell-command-on-region).
Within eshell, you can use
~ $ (with-current-buffer "*scratch*" (buffer-string)) | nl
1 ;; This buffer is for text that is not saved, and for Lisp evaluation.
2 ;; To create a file, visit it with <open> and enter text in its buffer.
Eshell commands are Emacs functions, e.g,.
(defun kitty ...