On Wed, Jun 29, 2011 at 9:34 AM, Bryce Stenberg <[email protected]> wrote:
> sed -r 'h; s/(.).*/\1/g; x; s/.(.*)/\1/g; s/(.{4})/\1Z/g; x; G;
> s/\n//g;'

Nice, but needs a little adjustment to match the original requirement
- you accidentally kept only the first character, not the first five.

$ echo abcdefghijklmnopqrstuvwxyz |  sed -r  'h; s/^(.{5}).*$/\1/; x;
s/^.{5}(.*)$/\1/; s/(.{4})/\1Z/g; x; G; s/\n//'
abcdefghiZjklmZnopqZrstuZvwxyZz

The ugly bit is the way sed appends the two storage spaces together,
introducing a newline.

However, removing the prefix into a separate space means you end up
with a nicer pattern than mine for appending the Z to .{4}, and as you
said, you don't have to assume there are no Zs in the input any more,
or use anchors of any kind (which defeat the /g).

-jim

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

Reply via email to