Score:2

Command using sed

us flag

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
Score:1
pl flag

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

\b boundary

karel avatar
sa flag
This should be the accepted answer.
Score:0
us flag
sed -i.bak 's/\<ole\>/new_string/g' file.txt 

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

Oslolosen avatar
us flag
Thanks! What does the <> stand for?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.