sed \ w字符类不适用于Mac上的替换 [英] Sed \w character class not working with replace on mac
本文介绍了sed \ w字符类不适用于Mac上的替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在OSX上执行此命令时,我希望每个字母都被一个"x"代替,但是没有一个字母被替换:
When I execute this command on OSX, I would expect each letter to be replaced by an "x", but none of the letters are replaced:
$ echo 'a b c' | sed 's/\w/x/g'
输出: a b c
这很好用:
echo 'a b c' | sed 's/[[:alpha:]]/x/g'
输出: x x x
我想念什么?
推荐答案
请注意,Mac上sed的BSD实现不同于其他linux计算机
Please note that the BSD implementation of sed on Mac is different from other linux machines
您可以安装gnu sed.在 Apple Mac OS 上运行以下命令:
You can install gnu sed. Run the following command on Apple Mac OS:
$ brew install gnu-sed
参考: https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/
这篇关于sed \ w字符类不适用于Mac上的替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文