EDIT: Misread your question as wanting to apply that change to the file you're working on. If you just want to run a shell command against a buffer, you can use shell-command-on-region
, which is usually bound to M-|
.
If you're just trying to get to a particular line number, M-x goto-line
works. I bind that to C-x C-l
by putting (define-key global-map "\C-x\C-l" 'goto-line)
in my ~/.emacs
.
Try this (in your ~/.emacs
file):
;;; Run a shell command on all text between the mark and the point and
;;; replace with the output.
(defun shell-command-in-region (start end command &optional flag interactive)
"Execute shell-command-on-region and replace the region with the output
of the shell command."
(interactive (list (region-beginning) (region-end)
(read-from-minibuffer "Shell command in region: "
nil nil nil 'shell-command-history)
current-prefix-arg
(prefix-numeric-value current-prefix-arg)))
(shell-command-on-region (point) (mark) command t)
)
(define-key esc-map "#" 'shell-command-in-region)
Invoke it by selecting a region you want to operate on and then doing M-#
.