On Tue, Jun 28, 2011 at 1:06 PM, Glenn Cogle <[email protected]> wrote:
> Hi all sed gurus (& wannabes like me),
>
> Wanting to `sed` beyond my present understanding;
>
> echo abcdefghijklmnopqrstuvwxyz | sed 'keep first 5 chars, then append a Z
> to every fourth char thereafter, and keep the leftovers too'
>
> ie
>
> abcdefghiZjklmZnopqZrstuZvwxyZz
> I think sed would be capable of this - but haven't proven it yet.
Perfectly capable of it.
Given that Z will never occur in your input string ...
You need a multiline sed invocation, using the branch feature.
$ echo abcdefghijklmnopqrstuvwxyz | sed -re '
> s/^(.{5})(.*)$/\1Z\2/
> :groupsoffour
> s/^(.*Z)([^Z]{4})([^Z]*)$/\1\2Z\3/
> t groupsoffour
> s/^(.{5})Z(.*)$/\1\2/
> '
abcdefghiZjklmZnopqZrstuZvwxyZz
I chose to slap a Z in just after the first 5 chars as the first thing ...
Then select four non-Zs following a Z, and give them a Z
Loop back and do it again if that s/// did any work
Then remove the temporary Z just after the first 5
-jim
_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users