As per sed whole word search and replace I have tried the following.
按照单词搜索和替换,我尝试了以下内容。
OS: HP-UX B.11.31 U ia64
操作系统:HP-UX B.11.31 U ia64
$ echo "bar bar2 embarassment" | sed "s/\<bar\>/test/g"
bar bar2 embarassment
$ echo "bar bar2 embarassment" | sed "s/\b[bar]\b/test/g"
bar bar2 embarassment
$ echo "bar bar2 embarassment" | sed "s/\[[:<:]]bar[[:<:]]\/test/g"
sed: Function s/\[[:<:]]bar[[:<:]]\/test/g cannot be parsed.
$ echo "bar bar2 embarassment" | sed "s/bar/test/g"
test test2 embraassment
None of the above are helping me to match the exact values.
以上都没有帮助我匹配确切的值。
Note: I can't install GNU sed
since I don't have permission to do so.
注意:我无法安装GNU sed,因为我没有权限这样做。
1 个解决方案
#1
1
Most portable method :)
最便携的方法:)
sed 's/^bar$/test/;s/ bar / test /g;s/^bar /test /;s/ bar$/ test/'
You can also allow all non-alphanum characters:
您还可以允许所有非alphanum字符:
sed 's/([^a-zA-Z0-9])bar([^a-zA-Z0-9])/\1test\2/g;s/^bar([^a-zA-Z0-9])/test\1/'
#1
1
Most portable method :)
最便携的方法:)
sed 's/^bar$/test/;s/ bar / test /g;s/^bar /test /;s/ bar$/ test/'
You can also allow all non-alphanum characters:
您还可以允许所有非alphanum字符:
sed 's/([^a-zA-Z0-9])bar([^a-zA-Z0-9])/\1test\2/g;s/^bar([^a-zA-Z0-9])/test\1/'