krasnoff krasnoff - 1 year ago 44
Linux Question

How to replace a string containing "\u2015"?

Does anyone know how to replace a string containing

in a SED command like the example below?

sed -ie "s/some text \u2015 some more text/new text/" inputFileName

Answer Source

You just need to escape the slashes present. Below example works fine in GNU sed version 4.2.1

$ echo "some text \u2015 some more text" | sed -e "s/some text \\\u2015 some more text/abc/"
$ abc

Also you don't have to use the -i flag which according to the the man page is only for editing files in-place.

-i[SUFFIX], --in-place[=SUFFIX]

    edit  files  in place (makes backup if extension supplied).  The default operation mode is to break symbolic and hard links.  This can be changed with --follow-symlinks and