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

Remove prepending character from block of lines in bash

I have a text file that has at some point a text like this:

[....previous text...]

#[ID1]
#my_url="http://miccheck12.com"
#your_url="http://miccheck12.com"
#comments=""

[....subsequent text...]

The block of text I’m interested in is identified by ID1. For all the block I want to remove the prepending character #.

I was trying to do this with sed. Given that for example sed -i 's/#\[ID1\]/\[ID1\]/g' file.txt works successfully, I’ve tried to extend this to the next line like: sed -i 's/#\[ID1\]\n#my_url/\[ID1\]/g' file.txt but it’s not catching the lines anymore. How can I solve this? I’m not even sure sed is the best approach.

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 :

Try:

sed '/^#\[ID1\]$/,/^$/s/^#//'

Between the lines ^#\[ID1\]$ and empty line, remove the leading #.

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