Issue
I tried to reformat headers in a markdown file with sed but somehow that doesn't seem to work. Problem is that between the header # sign(s) and the header text needs to be one space, otherwise it is not correctly displayed.
So i tried to run several variations of sed commands to add this space after the # signs
sed -i "s/<expression>/\1 /g" test.md
<expression> being:
^\(\s*#+\)
^\(\[#\]+\)
^\(\[\#\]+\)
-i should replace this inside the file, but when i review the file with cat test.md
, the space is still missing. I even added a backslash in front of the space in the substitute, but no luck.
The content of test.md is the following example data:
#Heading 1
Some text
- a list entry
- another one
##Heading 2
text
##Heading 3
The command should result in e.g. line 1 # Heading 1
What am i missing?
Solution
You need to escape the plus sign, e.g.:
^\(\s*#\+\)
Answered By - Michael Vehrs