Replace Line Feed with a Space in unix shell script

Possa picture Possa · Feb 18, 2011 · Viewed 15.6k times · Source

I have a text file containing some records. Each record is splitted in 4 rows (not always 4), like the example:

----
row1
row2
row3
row4
----
row1
etc...

Each row is ended with the Line Feed character (LF). Ok, I need to obtain the record in only one line, replacing the LF character with a Space, like in example:

---- row1 row2 row3 row4
---- row1 row2 ...etcetera

Any help or suggestion for the solution? Thanks in advance.

Answer

ajreal picture ajreal · Feb 18, 2011

maybe this can work ?

cat FILE | xargs | sed "s/ ---- /\n---- /g"