awk - How to rejoin lines in a file that have control ^M in a text field -


i exporting data 100's of udb tables .csv files. hitting issue using exported data since tables contain user text control characters breaking lines new lines. there way using sed or awk remove ^m , rejoin lines impacted ^m . clean on output have many tables hoping avoid checking there since majority of records fine.

example of broken lines need become single line

"91","2007-12-06-15.52.38.664462","c","the difference blah blah, blah blah, blah blah ^m ","49 ","2007-12-06-14.52.41.000000"," "91","2007-12-06-15.52.38.664462","c","pre  hard close^m ","n546 ","2015-06-16-14.23.26.000000","        "," " 

there should 2 lines there, split on 4 because of ^m characters.

with gnu sed:

sed '/\r$/{s///;n;s/\n//}' file 

if want edit file "in place" use sed's option -i.


Comments