How can I can insert the contents of a file into another file right before a specific line using sed?
example I have file1.xml that has the following:
I tried the different solutions and the one from Beta did the work for me.
Summary :
Example :
Create 2 files :
cloud_config.yml:
coreos:
__ETCD2__
etcd2.yml :
etcd2:
name: __HOSTNAME__
listen-peer-urls: http://__IP_PUBLIC__:2380
listen-client-urls: http://__IP_PUBLIC__:2379,http://127.0.0.1:2379
Then we run that script on it :
sed '/Standard/i __ETCD2__' cloud_config.yml \
| sed -e "/__ETCD2__/r etcd2.yml" > tmpfile
sed "s|__ETCD2__||g" tmpfile > cloud_config.yml
Finally, we got that :
coreos:
etcd2:
name: __HOSTNAME__
listen-peer-urls: http://__IP_PUBLIC__:2380
listen-client-urls: http://__IP_PUBLIC__:2379,http://127.0.0.1:2379