From: Andy Walker on 23 Apr 2010 16:00 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 23 Apr 2010 17:53 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 24 Apr 2010 11:13 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
First
|
Prev
|
Pages: 1 2 Prev: Allocate a new tty/pty Next: AWK question - split string into variables |