【问题标题】:How to handle UTF-8 emoji in sed on Cygwin?如何在 sed 中处理 UTF-8 表情符号?
【发布时间】:2019-03-21 22:04:19
【问题描述】:

我在 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 编码的,我使用的是 UTF-8 编码的 Cygwin,我的 SED 命令也在一个 UTF-8 编码的“.sh”文件中。

【问题讨论】:

  • 这个有问题的字符是这个:unicodelookup.com/#????/1 这个字符的十六进制值是:f0 9f 8e ba
  • 这个字符在任何方面都不特殊。确保您的语言环境是 UTF-8 语言环境。
  • 我无法用 GNU sed 4.5 重现您的问题。我复制粘贴了您的 sed 命令并输入到我的终端并得到了您的预期输出:content="<div class="wysiwyg added-oneshot">this is a ">????< test</div>".
  • 谢谢@Socowi,我尝试在 Cygwin 上使用 GNU sed 4.4。我将在另一个系统上尝试。

标签: bash sed unicode utf-8 emoji


【解决方案1】:

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

感谢您的关注。 我希望这个帖子可以帮助另一个 Cygwin 用户。

【讨论】:

    猜你喜欢
    • 2020-09-19
    • 2014-08-06
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 2016-03-28
    • 1970-01-01
    相关资源
    最近更新 更多