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

坚强是说给别人听的谎言 提交于 2019-12-23 17:27:46

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/35356408/removing-image-and-link-tags-in-markdown-md-file-using-bash-preferably-sed-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!