I want to replace string in file using sed/grep but the string is mingled with another strings
Example:
sed -i 's/php/vinu/g' test.yml # to replace string php with vinu
test.yml
php
phpehealth
dophp
testingphpin
In the above yml file contains multiple "php" strings, but I want to replace only "php" string with "vinu" and rest should not touch.
expected o/p:
vinu
phpehealth
dophp
testingphpin
/gflag. Remove the /g flag and it will work beatifully for you. Also if your string always starts withphpthen consider `/^php/vinu/g'line with php inside? Should thephpget replaced here? (The given answers would do so) Or do you only want to replace aphpin a line of it's own? (Then trys/^php$/vinu/)