Issue
From the sed manual, section 3.2 (sed commands summary):
D
If pattern space contains newlines, delete text in the pattern space up to the first newline, and restart cycle with the resultant pattern space, without reading a new line of input.
But in section 6.1 (how sed works) it explains that:
... first, sed reads one line from the input stream, removes any trailing newline, and places it in the pattern space ...
So I wonder, how can the pattern space contain any newline if sed reads the input until it reaches a newline, and then places this in the pattern space?
Solution
It can happen via the G
or N
commands:
G Append a newline to the contents of the pattern space, and then append the contents of the hold space to that of the pattern space.
N Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more input then sed exits without processing any more commands.
Answered By - IonuČ› G. Stan Answer Checked By - Mary Flores (WPSolving Volunteer)