Reputation: 26440
I want to replace a pattern in some lines:
I have tried
sed -i 's/pattern/new-string/g' ./file
But this replaces everything in the file. I want to replace the pattern only on those lines that match another-pattern
Any thoughts?
Upvotes: 1
Views: 96
Reputation: 785761
You can use this sed command:
sed -i '/another-pattern/s/pattern/new-string/g' ./file
This will perform substitution only on lines that match another-pattern
pattern.
Upvotes: 4