From: Andy Walker on
pk wrote:
> Well, there are indeed sed solutions, but they're not really pretty.
> For example, using a loop and a marker: [...]

You don't need the inserted newlines. Following works on my
machine [Kubuntu]; may need minor tweaking for some Seds.

$ sed ':b s/^\(a*\)a/\1c/; tb'

[same general idea -- as long as there are leading a's, replace the
last of them with a c and loop back].

--
Andy Walker
Nottingham
From: pk on
Andy Walker wrote:

> pk wrote:
>> Well, there are indeed sed solutions, but they're not really pretty.
>> For example, using a loop and a marker: [...]
>
> You don't need the inserted newlines. Following works on my
> machine [Kubuntu]; may need minor tweaking for some Seds.
>
> $ sed ':b s/^\(a*\)a/\1c/; tb'

Right, thanks for the improvement!

From: Stephane CHAZELAS on
2010-04-23, 22:53(+01), pk:
> Andy Walker wrote:
>
>> pk wrote:
>>> Well, there are indeed sed solutions, but they're not really pretty.
>>> For example, using a loop and a marker: [...]
>>
>> You don't need the inserted newlines. Following works on my
>> machine [Kubuntu]; may need minor tweaking for some Seds.
>>
>> $ sed ':b s/^\(a*\)a/\1c/; tb'
>
> Right, thanks for the improvement!

That's not standard syntax. I'm even surprised that it works in
any sed.

sed -e :b -e 's/^\(a*\)a/\1c/;tb'

would be standard and portable.

Without a loop:

sed 'h;s/[^a].*//;s/a/c/g;G;s/\na*//'

--
Stéphane