regex - Sed exact match search and replace on HP-UX -


as per sed whole word search , replace have tried following.

os: 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 parsed.  $ echo "bar bar2 embarassment" | sed "s/bar/test/g" test test2 embraassment 

none of above helping me match exact values.

note: can't install gnu sed since don't have permission so.

most portable method :)

sed 's/^bar$/test/;s/ bar / test /g;s/^bar /test /;s/ bar$/ test/' 

you can allow non-alphanum characters:

sed 's/([^a-za-z0-9])bar([^a-za-z0-9])/\1test\2/g;s/^bar([^a-za-z0-9])/test\1/' 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -