How to replace \w SED multiple matches on the same line without piping
SED's replacing mechanism replaces only the first occurrence each line. To change this, use the "/g" flag.
Example when sed replaces first match only:
Code:
[root@rhel5 ~]# echo "test test asdf test" >test.html
[root@rhel5 ~]# echo "test test asdf test" >>test.html
[root@rhel5 ~]# sed -i 's/test/replacement/' test.html
[root@rhel5 ~]# cat test.html
replacement test asdf test
replacement test asdf test
Example when sed replaces all matches on each line:Code:
[root@rhel5 ~]# echo "test test asdf test" >test.html
[root@rhel5 ~]# echo "test test asdf test" >>test.html
[root@rhel5 ~]# sed -i 's/test/replacement/g' test.html
[root@rhel5 ~]# cat test.html
replacement replacement asdf replacement
replacement replacement asdf replacement