sed whole word search and replace
How to replace whole words in string sed whole word search and replace
with sed in HP-UX (B.11.31)?
$ echo "bar embarassment" | sed "s/bar/no bar/g";
"\开发者_Go百科bbar\b" does not work
"\<bar\>" does not work
"[[:<:]]bar[[:>:]]" does not work
Try the -r
option of sed
with \b
:
echo "bar embarassment" | sed -r "s/\bbar\b/no bar/g";
Tested on solaris, not hpux
echo "bar embarassment bar foobar bar" |
sed -e 's/\([^[:graph:]]\)bar$/\1no bar/g' \
-e 's/\([^[:graph:]]\)bar\([^[:graph:]]\)/\1no bar\2/g' \
-e 's/^bar\([^[:graph:]]\)/no bar\1/g'
emits
no bar embarassment no bar foobar no bar
if you are in vim, you can use this command:
:% s/\<old\>/new/g
精彩评论