Search code examples
shellunixreplacespacelinefeed

Replace Line Feed with a Space in unix shell script


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.


Solution

  • maybe this can work ?

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