You can omit the contents of a pattern in sed and give it as //, which means to treat it as the same as the last regex used. By removing it, you change from deleting when a pattern is matched to always deleting.

I've added a couple of l commands before and after the substitution command

The sed command works as follows:

For the first time through only, add a newline to the pattern space /\n/!G

The regexp groups the first character \(.\) (AKA \1) and then everything upto the first newline \(.*\n\) (AKA \2) and then substitutes these two groups by the entire match & and then \2\1.

If the previous regexp is true following the substitution //D delete upto the first newline i.e. that is delete the previous & expression and begin a new cycle but do not read a new line. Effectively loops till the regexp fails.

Delete the first character i.e. the newline which has worked it's way to the front of the string s/.//