# sed -n 'H;$x;$s,\n,,gp' file ^ ^ ^ ^ | | | | | | | | | | | For the last line only, globally strip all line endings in the pattern space and print the result | | | | | For the last line only, swap the hold and pattern spaces | | | Append each line to the hold space | Don't print any lines - by default all lines are printed following processing