问题
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