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

Replace string with link in bash

I want to replace a sentence in a file this:
from

[Report 1](**Please put link here**)"
[Report 2](**Please put link here**)

to:

[Report 1](https://stackoverflow.com/09004cffcbee784a?docno=/link1)"
[Report 2](https://stackoverflow.com/09004cffcbee784a?docno=/link2)

So I tried with but it does not seem to make the replacement

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

sed -i 's#[Report 1](\*\*Please put link here\*\*)#(https://stackoverflow.com/09004cffcbee784a?docno=/link1)#g' file.md

>Solution :

Square brackets are special in sed regular expressions (they introduce character classes). You need to escape them by a backslash.

s#\[Report 1\)](\*\*Please put link here\*\*)#(https://stackoverflow.com/09004cffcbee784a?docno=/link1)#g

You may also capture the number after Report and resuse it in the link:

s#\[Report \([12]\)](\*\*Please put link here\*\*)#(https://stackoverflow.com/09004cffcbee784a?docno=/link\1)#g
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