sed over ssh

To use the sed substitute command you need the 's' option

The general syntax looks like this:

ssh -t user@server sudo sed -i.bak -f' script.sed file

-t: allocates a tty (terminal) so that you can then run sudo

-i: creates a backup with the .bak extension

-f: points to the .sed file on the remote server that needs to be run

script.sed : this is a script on the remote server that needs to be applied

file : this is the file to which the script is applied

The method is interesting, but it turns out that you first have to upload your .sed script to the remote server

Article author: Andrei Olegovich