tlacgw
Last Updated: February 25, 2016
·
2.536K
· bor

Detect newline(\n) in sed replacement

sed ':a;N;$!ba;s/\n/ /g'
  • create a register via :a
  • append the current and next line to the register via N
  • if we are before the last line, branch to the created register $!ba (`$! means not to do it on the last line (as there should be one final newline)).
  • the substitution replaces every newline with a space on the pattern space (which is the contents of the a register = the whole file)