包括带有regex和sed的扩展ASCII



我想选择所有字符,包括使用sed的正则表达式组中的扩展ASCII。

  • 下一步工作:
echo -e "TO BE REMOVED. THIS NOT. TO BE REMOVED" | sed -E 's/(TO BE REMOVED)(.{12})(.*)/IT WAS REMOVED2/g'

我得到:

IT WAS REMOVED. THIS NOT.
  • 但是,如果我在一个组中插入一个扩展的ASCII字符,它就不起作用:
echo -e "TO BE REMOVED. THISxa5NOT. TO BE REMOVED" | sed -E 's/(TO BE REMOVED)(.{12})(.*)/IT WAS REMOVED2/g'
  • 尝试在sed正则表达式中包含扩展的ascii字符,我可以执行以下操作:
echo -e "HI FRIEND, xa5 ARE YOU?" | sed -E 's/xa5/HOW/g'

这变成:

HI FRIEND, HOW ARE YOU?
  • 但如果我试图用方括号包含所有扩展的ascii字符,那就行不通了:
echo -e "HI FRIEND, xa5 ARE YOU?" | sed -E 's/[xa0-xfe]/HOW/g'

我得到输入

HI FRIEND,  ARE YOU?

这可能对你有用(GNU sed(:

sed 's/[^[:print:]]/HOW/g' file

请参阅此处了解更多信息。

相关内容

  • 没有找到相关文章

最新更新