Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sed multi line pattern

I need to search for the following

[ec2_server]
server_host=something

[list_server]
server_host=old_name

to

[ec2_server]
server_host=something

[list_server]
server_host=new_name

Since the server name is in square bracket I had challenges with sed special characters. Also I cannot just search and replace server_host, it needs to be list_server host that needs to be changed. Its a multiline search and replace command

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This will replace the first line after [list_server]:

awk '/\[list_server]/ { print; getline; $0 = "server_host=new_name" } 1'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading