I want to extract markdown from some sort of text (ulysses iii iCloud Text.txt file). The editor replaced all square brackets with the "OBJECT REPLACEMENT CHARACTER" 0xEF 0xBF 0xBC (efbfbc)
and I want to undo this operation.
How can I substitute all odd occurrences with "[" and all others by "]".
EDIT:
As example I want to replace each occurrence of x
to [
or ]
:
Some xlinkx
-> Some [link]
You can use
sed
for your purpose. Withsed -i
it will edit the file in place making the changes needed. To create a backup of the original infile.bak
usesed -i.bak
. The expression would require that you place the character you want to replace in the variablechar
(e.g.char=x
in your example). Then the following would replace all occurrence ofx..stuff..x
with[..stuff..]
:Example:
The expression utilizes word boundaries
\b
to control the match at the beginning and end of the experssion to insure first occurrence is replaced with[
and the second with]
.