unix - sed: How can I replace a newline (\n)? - Stack Overflow I unsuccesfully tried: sed 's#\n# #g' file sed 's#^$# #g' file. How to fix it? ... Or use this solution with sed: sed ':a;N;$!ba;s/\n/ /g'. This will read the whole file in a loop, ...