Sed \w character class not working with replace on mac

拟墨画扇 提交于 2021-02-05 12:28:46

问题


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'

output: a b c

This works just fine:

echo 'a b c' | sed 's/[[:alpha:]]/x/g'

output: x x x

What am I missing?


回答1:


Please note that the BSD implementation of sed on Mac is different from other linux machines

You can install gnu sed. Run the following command on Apple Mac OS:

$ brew install gnu-sed

reference: https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/



来源:https://stackoverflow.com/questions/59447514/sed-w-character-class-not-working-with-replace-on-mac

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!