ed-mode lets you interact with Emacs buffers like you would do with the ed editor.
Make sure that ed-mode.el is in your load-path, then add
(require 'ed) to your init file.
Use ed by opening a file like you’d normally do, and then do: M‑x ed RET