N adds a newline to the pattern space, then appends the next line of input (with any trailing \n removed) to the pattern space. So when the cycle starts (we have just one cycle here), sed reads the first line of input, removes any trailing \n and places it in the pattern space, then it processes the script: b: Branches unconditionally to the specified label.$!: Don't execute the following command on the last line.N: Adds a newline to the pattern space, then appends the next line of input (with any trailing \n removed) to the pattern space.You also may omit -i and redirect the output to an arbitrary file. i tells sed to replace your file with the result of the script,Īnd if you supply a SUFFIX, a backup will be created with that suffix. \r\n and \r, you can use this sed script (this is an all-in-one solution and of course, you can also use it if your file merely has \r\n or \r line breaks):