How can I replace a pattern only on lines that do or do not contain another pattern?

Viewed 10528

Say I have a text containing the words red and blue.

How do I replace occurences of the word blue with the word green only in all lines containing the word red?

Likewise how can I replace blue with green in all lines NOT containing the word red?

2 Answers
Related