kyprio kyprio - 1 month ago 6
Markdown Question

convert html links to markdown using command sed

I am editing a bash script to convert html into markdown and i found myself stuck with that tag :

<a href="www.link.com">Link</a>


which should looks like this in markdown

[Link](www.link.com)

Answer

I found something with sed and the pattern selectors \1 \2

echo '<a href="www.link.com">Link</a>' | sed 's/<a href="\(.*\)">\(.*\)<\/a>/[\2](\1)/'
[Link](www.link.com)

The pattern you place between parenthesis \( and \) will be stored in a variable \1 then the next one will be in \2 ...