I have this ssh config that needs to be edited.
Host vps6
HostName 123.456.789.00
User dylan
Port 123
Host vps4
HostName 123.456.789.00
User dylan
Port 123
# old server
Host vps3-old
HostName 123.456.789.00
User dylan
Port 123
I want to move config for vps6
to end of file and append -old
to its config alias. The resulting file would be.
Host vps4
HostName 123.456.789.00
User dylan
Port 123
# old server
Host vps3-old
HostName 123.456.789.00
User dylan
Port 123
Host vps6-old
HostName 123.456.789.00
User dylan
Port 123
I managed to do exactly that using this sed command → sed '/'"vps4"'/{N;N;N;N;H;$!d}; ${p;x;s/'"vps4"'/'"vps4"'-old/}'
, unfortunately this gives me unwanted newline at the end of file.
[tmp]$ sed '/'"vps6"'/{N;N;N;N;H;$!d}; ${p;x;s/'"vps6"'/'"vps6"'-old/}' config
Host vps4
HostName 123.456.789.00
User dylan
Port 123
# old server
Host vps3-old
HostName 123.456.789.00
User dylan
Port 123
Host vps6-old
HostName 123.456.789.00
User dylan
Port 123
[tmp]$ # See above me
Moreover, I want to be able to specify the next n line to be moved (for example above will be mark Host vps4
and next 3 line to be moved to end of file). I have searched up the net and found out that the recommended tools for this kind of task is ed
, but I have yet to find out the example command to do exactly what I want.