OK, we have a new proposed solution from Joe at the pub last night,
which takes the prefix and moves it straight to the end of the string,
then does the /(.{4})/\1Z/g substitution, then tries to grab the
original prefix from the end of the string and fix it up at the
beginning.
I got a little stuck at the fixup when I tried to remove the Zs that
ended up in the original prefix at the same time as bring the prefix
back to the beginning -- because I'd used (.*) to grab the front of
the string, sed was having to backtrack to identify the old prefix,
and the traditional NFA engine it uses halts at the first match,
instead of doing the POSIX thing of choosing the longest match.
(Yes, I have a copy of "Mastering Regular Expressions" and I've read
it thoroughly more than once)
But once I did away with the combined job and split it into two
different matches, everything works just fine.
Here's the test :-
for i in abcdefghijklmnopqrstu \
abcdefghijklmnopqrstuv \
abcdefghijklmnopqrstuvw \
abcdefghijklmnopqrstuvwx \
abcdefghijklmnopqrstuvwxy \
abcdefghijklmnopqrstuvwxyz
do
printf "$i -> "
echo $i | \
sed -r 's/^(.{5})(.*)/\2\1/; s/(.{4})/\1Z/g;
s/(.{1,4})Z(.{1,4})Z?$/\1\2/; s/(.*)(.{5})$/\2\1/'
done
abcdefghijklmnopqrstu -> abcdefghiZjklmZnopqZrstuZ
abcdefghijklmnopqrstuv -> abcdefghiZjklmZnopqZrstuZv
abcdefghijklmnopqrstuvw -> abcdefghiZjklmZnopqZrstuZvw
abcdefghijklmnopqrstuvwx -> abcdefghiZjklmZnopqZrstuZvwx
abcdefghijklmnopqrstuvwxy -> abcdefghiZjklmZnopqZrstuZvwxyZ
abcdefghijklmnopqrstuvwxyz -> abcdefghiZjklmZnopqZrstuZvwxyZz
-jim
_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users