Command Using Sed

Command Using Sed

I have a problem. I want to change ole without changing dole in this file. I've tried to use:

sed -i s/^ole$/kari/ file.txt

Is there any way to change this without using two command lines as:

sed -i s/^ole/kari/ file.txt; sed -i s/ole$/kari/ file.txt

cat file.txt

ole duck
doffen duck
dole duck
duck, ole

2 Answers

sed -e s'/\bole\b/kari/g' file.txt

\b boundary

1
sed -i.bak 's/\<ole\>/new_string/g' file.txt 

In this case new_string would be kari (without quotes) if I understood correctly.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.