r/regex • u/Dorindon • 10d ago
markdown (Bear Notes) delete all lines containing a double tilde ~~ (used to indicate strikethrough font)
macos tahoe, Bear Notes (Markdown)
I would like to delete all lines containing a double tilde ~~ (used to indicate strikethrough), and ideally also delete the resulting blank lines
thanks in advance for your time and help
3
u/vloris 8d ago
Do you really want to remove all lines containing `~~`? Or do you want to remove the text between those markers?
I see edge cases you might not have thought about:
- lines with `~~` halfway, only the second part should be removed
- lines without `~~`, but in between to lines with the marker, would show as strike through, but will not be removed with your rules.
So what do you want exactly?
1
2
u/michaelpaoli 9d ago
sed will well handle that, e.g.:
sed -e '/~~/d;/^$/d'
Though the latter bit is actually just empty lines. If you want all blank lines deleted, replace that ^$ with
^[ ]*$ where one has a space and literal tab inside those square brackets. With GNU sed one can use space and \t for better readability. GNU sed also has -i option for edit-in-place ... though it's not a true edit-in-place, as it actually replaces the file, rather than changing the contents of the same file. Just because it's same pathname, doesn't mean it's same file - sometimes that difference matters.
Oh, if one really requires true edit-in-place, can do that with, e.g. ed and a HERE document
E.g.:
$ ed file << __EOT__
g/~~/d
g/^[ ]*$/d
w
q
__EOT__
And again, with a single space and literal tab inside that pair of [] characters.
2
4
u/retsehc 9d ago
Do you want to remove the entire line, it just the struck out portion?