question
optimize markdown documents with sed
introduce
You are the document inspector of the shiyanlou, need to check document format every day, a document found in different marks appear blank between too much (provisions require only a blank document appeared in 2, 3 cases), and all the image formats are written into the link, need you use this document to quickly repair Sed.
For example, a document does not regulate instances and link errors:1
2
3
4
5
6
7
8
9## title one
## Title Two
## Title Three
[picture-1] (https://www.shiyanlou.com/test.png)
Title Two and Title Three require only one empty line directly.
you should execute the Sed script in this way:1
Sed -f /home/shiyanlou/fix-format.sed document
After execution, the document is turned into:1
2
3
4
5
6
7## title one
## Title Two
## Title Three
[picture-1] (https://www.shiyanlou.com/test.png)
target
- The script path must be placed in the
/home/shiyanlou/fix-format.sed
- The way to call is:
sed -f /home/shiyanlou/fix-format.sed
document - Delete extra repeat blank lines in a document
- revising the format of the picture link
Hint
sed matching empty lines
the hints of the picture link are all in [picture-xxx] format, and the suffix of the address is.Png or.Jpg
test document download link: http://labfile.oss.aliyuncs.com/courses/980/test-document.md
Knowledge point
- regular expression
- Sed
keypoint
delete rows retain only one line
1
2
3
4/^$/{
N
/^\n$/D
}replace
1
s/\[picture/\!\[picture/
Note that the escape character