by Jeremy Canfield | Updated June 1st, 2018
Let's say file.txt contains newlines after text.
Hello World How are you today?
The sed command can be used to replace the new lines with something else. In this example, new lines are replaced with a single whitespace.
- :a and a are a label. You could replace a with some other label.
- N gets the current line and the next line.
- $! means do not continue when the last line has been reached.
- ba means go to label a.
- s|\n| |g is the sed replacement command.
~]# sed ':a;N;$!ba;s|\n| |g' file.txt Hello World How are you today?