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).
Asked
Active
Viewed 104 times
1

altendky
- 4,176
- 4
- 29
- 39
-
Some suggestions using perl here: http://stackoverflow.com/questions/6280388/perl-regex-replace-in-same-case – user1717259 Apr 24 '14 at 13:08
-
1Is it really only one character that you are looking to replace? if so, `sed -e 's/a/b/g' -e 's/A/B/g'` might do the trick. – iruvar Apr 24 '14 at 13:27
-
1@1_CR well, if it is really only one character, this would do: `sed 'y/aA/bB/'` – FloHimself Apr 24 '14 at 13:34
-
@1_CR I presently have duplicates as you show but am trying to avoid the repetition of the rest of the expression (question edited to clarify). – altendky Apr 24 '14 at 13:40
-
@FloHimself That led me to `sed -P '/(?
– altendky Apr 24 '14 at 13:50
1 Answers
1
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.

potong
- 55,640
- 6
- 51
- 83