Issue
I'm on macOS 12.6 and have an issue with the multiline commands in sed.
From this script (taken from the manual):
seq 6 | sed -n 'N;l;D'
I should get this output:
1\n2$
2\n3$
3\n4$
4\n5$
5\n6$
But this is what I get:
1$
2$
2$
3$
3$
4$
4$
5$
5$
6$
I can't figure out why the newline isn't printed unambiguously (that's what the "l" command does)
Thanks in advance!
Solution
why the newline isn't printed unambiguously
Because you are using BSD sed, not GNU sed, the newline is printed "ambiguously".
https://github.com/chimera-linux/bsdsed/blob/master/process.c#L627 -> prints a $
+newline on newline. (The check above when the line is longer than terminal width.)
I should get this output:
l
command is not standardized. Every sed can do what it wants with it. GUN sed prints it that way, BSD sed prints it the other, you can't expect.
Answered By - KamilCuk Answer Checked By - Willingham (WPSolving Volunteer)