Emacs can edit remote files transparently (as if they were local).
Whenever Emacs asks for a file, you can indicate a remote file like so: /myname@remotehost:/remote/path/to/file. Emacs retrieves the file over SSH, FTP, or another method and takes care of saving it when you're done.
Emacs can record macros and execute them over a region.
use C-x-( to start recording
use C-x-) to end recording
use <esc>-x -> apply-macro-to-region-lines
kmacro-start-macro C-x (
Command: Record subsequent keyboard input, defining a keyboard macro.
kmacro-end-macro C-x )
Command: Finish defining a keyboard macro.
Command: End kbd macro if currently being defined; else call last kbd macro.
apply-macro-to-region-lines M-x ... RET
Command: Apply last keyboard macro to all lines in the region.
call-last-kbd-macro M-x ... RET
Command: Call the last keyboard macro that you defined with \[start-kbd-macro].