>echo abcdefghijklmnopqrstuvwxyz | sed 'keep first 5 chars, then append
a Z to every fourth char thereafter, and keep the leftovers too'

Had another look at this last night, if you still interested in a purely
sed solution the following works I think (on Linux Mint at least - you
will need to escape the regular expression stuff since you don't have
-r). Also doesn't care if there are already 'Z's in the line:


sed -r 'h; s/(.).*/\1/g; x; s/.(.*)/\1/g; s/(.{4})/\1Z/g; x; G;
s/\n//g;'

        
Terrible stuff to read however so breaking it down

h;              = copy pattern space (input) to hold space
 
s/(.).*/\1/g;   = get the first character only

x;              = swap pattern and hold spaces (so now working against
original input)

s/.(.*)/\1/g;   = remove the first character

s/(.{4})/\1Z/g;         = every fourth character add in a Z

x;              = swap pattern and hold space again (pattern now has 1st
char, hold has Z'd stuff)

G;              = append hold space to pattern space     

 s/\n//g;               = remove the newline inserted when space above
got appended.

Regards,
  Bryce Stenberg.




DISCLAIMER: If you have received this email in error, please notify us 
immediately by reply email, facsimile or collect telephone call to +64 3 
9641200 and destroy the original.  Please refer to full DISCLAIMER at 
http://www.hrnz.co.nz/eDisclaimer.htm






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

Reply via email to