Re: reducing redundant lines, partially

"Jim Hill [email protected] [sed-users]" <[email protected]> Sun, 20 Nov 2016 14:24:08 -0800
Newsgroups gmane.editors.sed.user
Message-ID <CAEE75_2cJgXpYEDUVneUsf55aTJXT9zRDy+oVPvDpYHXvOpxyA@mail.gmail.com>
On Sun, Nov 20, 2016 at 1:33 PM, Thierry Blanc [email protected]
[sed-users] <[email protected]> wrote:
> :eep;
> N;
> s|^([^:]*):([^\n]*)\n\1|\1:\2|;
> teep;
> P;D

> The 3. line: s|^
> Why is the ^ needed? Without it, the script hangs or loops forever.

I think it's that, without the `^`, `\1` in that will always match at
least the null string before the colon so it will start endlessly
duplicating what follows.  I don't yet see why it hangs or loops,
though, unless your tests are all large enough that the O(2^n) on line
count (or swapping to store it) gets you, because the `N` in the loop
should finish it eventually.

Mine should verify the `:` terminator to avoid  errors like
`test1:20\ntest:21`.producing `test1:20:21` popping up on unsorted
input.

#!/bin/sed -Ef
:a
N
s/(([^:\n]*):[^\n]*)\n\2(:.*)/\1\3/
ta
P
D