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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like