I have a text file named "data" with the content:
a
b
c
abc
I'd like to find all "abc" (doesn't need to be on the same line) and replace the leading "a" to "A". Here "b" can be any character (one or more) but not 'c'.
(This is a simplification of my actual use case.)
I thought this perl command would do
perl -pi.bak -e 's/a([^c]+?)c/A\1c/mg' data
With this 'data' was changed to:
a
b
c
Abc
I was expecting:
A
b
c
Abc
I'm not sure why perl missed the first occurrence (on line 1-3).
Let me know if you spot anything wrong with my perl command or you know a working alternative. Much appreciated.
perl -0777pe 's/a([^c]+)c/A$1c/g'orperl -0pe 's/a([^c]+)c/A$1c/g'