Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing image and link tags in markdown (md) file using bash, preferably sed, command

I have markdown (md) files, on a git wiki, that I am changing to html. I don't want to include the images and links in the html file. Our images in markdown looks like this:

![Alt text](/path/to/img.jpg "Optional title")

Where as our markdown links looks like:

[I'm an inline-style link](https://www.google.com)

The only real different is the '!' character. I am writing a shell script to do everything. What is a bash command(s) to remove the entire image and link tag? Here is a more basic sed stack question:

How to remove square brackets and any text inside?

ps. can you include a smile in your answer? I am tired and want to go home.

like image 675
Jordan Stewart Avatar asked Oct 19 '22 15:10

Jordan Stewart


1 Answers

This should remove them both:

$ sed 's/\!\{0,1\}\[[^]]*\]([^)]*)//g' file.md

This works too but... see potong's comment here below:

$ sed 's/!\?\[.*\](.*)//g' file.md
like image 87
mauro Avatar answered Oct 21 '22 06:10

mauro