Skip to main content

remove newlines with sed(1)

There's always something new to learn when working with sed. Although using this beast for quite a while, I just discovered that sed is *really* working line-by-line. That's why things like this sed 's/\n/ /' won't work as expected (removing the newlines). Yes, tr could do this: tr '\n' ' ' ...but it's not as flexible as sed(1). So I found this: sed ':a;N;$!ba;s/\n//g' ...which is working just fine with GNU/sed 4.1.2 but won't work with the version of sed from Solaris10:

  sed ':a;N;$!ba;s/\n//g'
  Label too long: :a;N;$!ba;s/\n//g
What now?