Replace newlines with in a file in Linux bash

Home > Search
  by

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.

~]# sed ':a;N;$!ba;s/\n/ /g' file.txt
Hello World How are you today?


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments