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)
Written by Sergiy Borodych
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#