On 1 July 2011 15:24, Jim Cheetham <[email protected]> wrote:
> On Fri, Jul 1, 2011 at 2:28 PM, Kent Fredric <[email protected]> wrote:
>> Found an edge case:  abcd -> abcdZ
>>
>> https://gist.github.com/1057759
>
> Fantastic!
>
> Now I have to think about how to prevent it from happening (or
> actually, how to clean up afterwards), and whether preventing it is
> even necessary, given the original problem description.
>
> Hey Glenn, care to share some comments about what you were really
> doing with this? And what your limited platform is?
>
> -jim
>
> _______________________________________________
> Linux-users mailing list
> [email protected]
> http://lists.canterbury.ac.nz/mailman/listinfo/linux-users
>


Goofed around and read some man pages, discovered the "branch" "command".

sed -r -e '
{ /^.{0,5}$/b ;
s/^(.{5})(.*)/\2\1/;
s/(.{4})/\1Z/g;
s/(.{1,4})Z(.{1,4})Z?$/\1\2/;
s/(.*)(.{5})$/\2\1/
}'

https://gist.github.com/1057900

This resolves the 'abcd' -> 'abcdZ' edge case.

However, I also contemplated that perhaps:

abcdefghi -> abcdefghiZ  may also be considered "wrong" , but thats
hard to fix without massive changes. ( there's a magic property of
this problem that will only work as long as the "first" value is 5 and
the "Second" value is 4.  Adjust either of these by 1 and it injects
Z's in the characters that have been moved to the right hand end.

And thats hard to solve without temporary variable storage or
lookaround ( the latter of which is not supported by POSIX sed as far
as I can tell )


-- 
Kent

perl -e  "print substr( \"edrgmaM  SPA NOcomil.ic\\@tfrken\", \$_ * 3,
3 ) for ( 9,8,0,7,1,6,5,4,3,2 );"

http://kent-fredric.fox.geek.nz

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

Reply via email to