Re:Useful one-line scripts for sed (2005)
by zurn on Thursday June 08, 2017 @01:36AM
(#14512134)
Widely useful pick of the bunch:
[ Parent
| on HN ]
Re:Useful one-line scripts for sed (2005)
by majewsky on Thursday June 08, 2017 @04:47AM
(#14512842)
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}'
Re:Useful one-line scripts for sed (2005)
by predakanga on Thursday June 08, 2017 @02:51AM
(#14512401)
I've found that pattern to be very useful when altering/sanitising MySQL backups.
# Set the engine of all tables in schema `foo` to TokuDB
sed -re '/^USE `foo`/,/^USE / s/^\) ENGINE=\S+/) ENGINE=TokuDB/'