如何替换字符串 sed整个单词搜索和替换中的整个单词
在 HP-UX (B.11.31) 中使用 sed?
$ echo "bar embarassment" | sed "s/bar/no bar/g";
"\bbar\b" does not work
"\<bar\>" does not work
"[[:<:]]bar[[:>:]]" does not work
如何替换字符串 sed整个单词搜索和替换中的整个单词
在 HP-UX (B.11.31) 中使用 sed?
$ echo "bar embarassment" | sed "s/bar/no bar/g";
"\bbar\b" does not work
"\<bar\>" does not work
"[[:<:]]bar[[:>:]]" does not work
尝试使用-r
选项:sed
\b
echo "bar embarassment" | sed -r "s/\bbar\b/no bar/g";
在 solaris 上测试,而不是 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'
发出
no bar embarassment no bar foobar no bar
如果你在 vim 中,你可以使用这个命令:
:% s/\<old\>/new/g