Editing multiple lines at same time


sed has the ability to load multiple lines of text in its edit buffer. This allows you to observe one line and edit both, including merging them.
N - Next. Fetch (append) the next line into the edit buffer. Leave the current line in buffer and don't print to output. This can be performed multiple times. The linefeed is left in buffer between lines. The following with merge each pair of lines. N combines lines in edit buffer substitute replaces the linefeed with a space. sed -e "N" -e "s/\n/ /" data
D - deletes all text in the edit space up to and including the 1st new-line. Generally, paired with N to get desired effect. It then breaks the edit-cmd loop. It does NOT read in a new line of text from data file. It does not print the current line in the loop. And it leaves any text after the 1st new-line in the edit buffer. sed then reads in next line of data and starts the edit sequence again.
P - Print. Prints up to the 1st new-line in edit buffer. Most often used with N.