0

Using sed, I am attempting to recursively search and replace a string foo that may have characters before it as well as after it.

For examples:-

"foo_

'foo_abc

I want to specifically replace foo with foobar so that my example above will become:-

"foobar_

'foobar_abc

I am not succeeding with:-

find . -name "*.py" | xargs sed -i '/*foo*/{s/foo/foobar/g}'

What should I do instead to search and replace successfully?

1 Answer 1

2

Removing the *'s should do, and you don't need the initial /foo/:

find . -name "*.py" | xargs sed -i 's/foo/foobar/g'
Sign up to request clarification or add additional context in comments.

1 Comment

O yes. you are right. I got confused because some strings are actually in .html files and I was only replacing stuff in my .py files. My bad.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.