I'm trying to find all instances of aaa
and replace it with bbb
but preserving the first character preceding the aaa
. Here's how I'd do it in PHP with PCRE:
preg_replace('#(.?)aaa#', '\1bbb', 'aaasdfg');
How would I do something like that with sed? Here's my attempt (didn't work):
sed -i.bak -r 's/(.\?)aaa/\1bbb/g' filename.ext
It's a bit of a contrived example. What I'm trying to do is a little more complicated but, long story short, I'm trying to get .?
working.
Any ideas?