How to remove just LF from file?

I have a file with the data which looks like this

I open in Notepad++ and see the special characters

1111,FILE, TEST,787CR/LF
3333,FILE,78LF
7CR/LF

This is csv file transferred to unix. When i open in vi, there are three records with a ^M at the end of each line.

The 2nd and 3rd record are infact a single record. How do I remove the LF from the 2nd record and read 2nd and 3rd record as a single record.

I want the output as

1111,FILE, TEST,787CR/LF
3333,FILE,787CR/LF
tr -d '\r' < infile.csv > outfile.csv
1 Like

I tried this, but its giving the same output, only this is when I open through vi there is no ^M character at the end..

Please be aware that above is a non-standard file format on *nix which doesn't recognize those <CR> chars. You might need to remove those to get a standard *nix text file; see Aia's proposal.
For exactly your request and your data from post#1, try

awk '{while (!/\r$/) {getline X; $0 = $0 "," X}} 1' file
1111,FILE, TEST,787
3333,FILE,78,7

The <CR> chars from the input file are still there (as requested) but invisible in the printout.

 sed -r  ':l /$/{ N; s/([^/])LF\n/\1/} ;bl' csvfile
1 Like

Thank you!!. This gives me what I want, but can you tell me how this works?

If a line does not have a trailing <CR> ( = \r = 0x0D = ^M) it keeps getting more lines and appending them until a <CR> is found. Then print the entire construct as one line.