如何处理sed中的UTF-8表情符号?

时间:2018-10-17 09:14:55

标签: bash sed unicode utf-8 emoji

我已经看到许多有关在SED中转义和替换特殊字符的主题,但没有一个对我有帮助。

我有一个需要在文件上使用的sed命令:

sed -i "s/This[^\|]\+/& (cool) /g" "file.txt"

由于我不了解的原因,它适用于以下测试案例:

This is my funny  char and this | char is the char after which  i want to stop my job.

...并将其转换为:

This is my funny (cool) ڠchar and this | char is the char after which  i want to stop my job.

...而不是:

This is my funny  char and this | (cool) char is the char after which  i want to stop my job.

有人可以告诉我如何处理这种情况吗?

注意:该文件是UTF-8编码的,我使用的是Cytwin,它是UTF-8编码的,而我的SED命令也位于UTF-8编码的“ .sh”文件中。

1 个答案:

答案 0 :(得分:-1)

该错误似乎是由于我在CYGWIN上使用了SED,因为它在GNU Linux上运行良好。

感谢您的关注。 我希望该线程可以帮助其他Cygwin用户。