altendky
altendky

Reputation: 4344

Case insensitive match but matching replacement case

How can I adjust sed -e 's/(match other stuff too)[aA]/\1b/g' to have the replacing b match the case of the a being replaced? In this case only the single character is being replaced but the entire search can/should be case insensitive (I can address that separately with s///I I believe).

Upvotes: 1

Views: 130

Answers (1)

potong
potong

Reputation: 58420

This might work for you (GNU sed):

sed -rn 's/$/\nabAB/;:a;s/(match other stuff too)([aA])(.*\n.*\2(.).*)/\1\4\3/;ta;P' file

Append a lookup table to the end of the line and loop until all lookups have been substituted.

Upvotes: 1

Related Questions