i am not a sed mayven, so i read the man page (man sed) which includes : label - Label for b and t commands n N Read/append the next line of input into the pattern space t label - conditional branch
I also made a test file to edit So, /^$/N gets rid of blank lines not sure of the rest
In my test, I had following findings: /^$/N search empty lines and N tells to search pattern that are split into 2 lines or immediately quit when reading the End-of-File. s/^\n// remove the newline characters So, I got the same conclusion: this can remove the empty lines from the input.
Yes, that code eliminates empty (null) lines. For each null line encountered, it pulls the next line into the pattern space (main work buffer), then deletes the null line at the front of the pattern space. Doing it that way requires for it to loop so that it can delete multiple null lines in succession. Without the loop, if it encountered several null lines in succession, it would delete only the first of each pair of null lines.
As tspj88 says, the s/^\n// is what actually eliminates the null line. That substitution command eliminates the newline character, which is all that a null line is composed of. But that newline character would not be available for elimination with a substitution command without pulling a second line into the buffer with the N command. You cannot eliminate the newline character at the end of the only (or last) line in the pattern space. If you have 5 lines in the pattern space, you can act upon the 4 newline characters that separate those lines.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE