The standard format of the file is:
Host example
HostName example.com
Port 2222
Host example2
Hostname two.example.com
Host three.example.com
Port 4444
Knowing the host's short name, I want to remove an entire entry in order to re-add it with new details.
The closest I have got is this, except I need to keep the following Host declaration and the second search term will capture two many terms (like HostName
):
sed '/Host example/,/\nHost/d'
My final solution (which is somewhat OSX orientated) was this. It's largely based on Cyrus' earlier answer.
This is more resilient to
HostName
directives which aren't indented.With GNU sed:
Output: