I'm trying to replace bobearl
with jim
in the following string
"billy" "bobearl" and "johnny"
I can do something like this:
sed 's/bob/jim/' /tmp/text.txt
"billy" "jimearl" and "johnny"
but that leaves earl
I can do this:
sed 's/bob.*/jim/' /tmp/text.txt
"billy" "jim
But that removes everything after the replacement string.
What is the most efficient way to replace bobearl
with jim
while not changing anything else? I assume my issues has something to do with the quotes but I'm just not sure how to get it to work.
bobearl
to match with in the substitution. Do you have any restrictions that you haven't told us about that prevents you from doing that?sed 's/"bob[^"]*"/"jim"/'
to make sure it only replaces double-quoted strings that start withbob