4 ms·
I use stuff like that all the time with config files where sections span multiple lines. For example, if ~/.ssh/config has a section like Host example Ho
by majewsky 9y ago
I use stuff like that all the time with config files where sections span multiple lines. For example, if ~/.ssh/config has a section like
Host example
HostName example.com
IdentityFile ~/.ssh/id_example
Port 1234
Host next
...
Then the following selects the identity file:
sed -n '/^Host example/,/^Host\>/{/^\s*IdentityFile/{s/^\s*IdentityFile\s*//;p}}' ~/.ssh/config
Although I would probably use awk after sed because it handled space-separated fields nicer:
sed -n '/^Host example/,/^Host\>/p' ~/.ssh/config | awk '$1=="IdentityFile"{print$2}'