I can't stop thinking about this ... :-) Luckily I have time for real
work in between ...

Here's another approach, without using tricks like branching or
multiple spaces. It's more Hofstadteresque, I think
http://xkcd.com/917/


$ echo abcdefghijklmnopqrstuvwxyz | \
> sed -r 's/(.{4})/\1Z/g; s/^(.{4})Z(.{4})/\1\2/; s/Z(.)/\1Z/g; s/(Z.{3})Z$/\1/'
abcdefghiZjklmZnopqZrstuZvwxyZz

Start by putting a Z in every 4th character :- abcdZefghZijklZmnopZqrstZuvwxZyz
Take out the first Z, which will be in the wrong place :-
abcdefghZijklZmnopZqrstZuvwxZyz
Move all the Zs along by one space :- abcdefghiZjklmZnopqZrstuZvwxyZz
Remove the last Z if the last group is now 3 chars :-
abcdefghiZjklmZnopqZrstuZvwxyZz

The target result has Zs just after original char 9, 13, 17, 21 ...
So, after the first sub, we have Zs just after original char 4, 8, 12,
16, 20 ... etc
Removing the first Z leaves us with chars 8, 12, 16, 20 ...
Then we shift the Zs along by one, giving 9, 13, 17, 21 ...
Finally, correct the last group of that shift results in a terminal
group of Z.{3}Z

-jim

_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users

Reply via email to