I'm trying to search and replace a string in all files matched by grep on a linux machine. I've got some pieces of what I want to do, but I'm unsure how best to string them all together.
grep -n 'foo' *
will give me output in the form:
[filename]:[line number]:[text]
For each file returned by grep, I'd like replace "foo" with "bar" and write the result back to the file. Is there a good way to do that? Maybe a fancy pipeline?
UPDATE:
I've modified my question to hopefully make it clearer.