Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142646

Remove LF inside specific field and nowhere else

$
0
0

I have been asked to clean data up in a MongoDB collection we have to stored addresses and generic customer contact data.

Data contains occasionally carriage returns that tend to break the load process when I push the data into a MySQL table. My code uses Javascript to do a replace(/\n//g, '') on the critical fields. However, the data dump still shows up messy as shown here:

"_id"|"UserID"|"PhoneNumber"|"Source"|"PrivateLabelID"|"OptOut"|"Blocked"|"Deleted"|"Note"|"CreatedAt"|"UpdatedAt"|"FirstName"|"LastName"|"Email"|"Custom1"|"Custom2"|"Custom3"|"Custom4"|"Custom5"|"GroupIDs""5e37169df3369f47583355dc"|"127342"|"8645169963"|"1"|"1"|"undefined"|"undefined"|"undefined"|"Timothy.. I mainly buy in the SW area of Florida. Please send me what you have"|"1580668573"|"1580668573"|"Lee"|"Burnside"|"clemsonworldentertainment@gmail.com"|"undefined"|"undefined"|"undefined"|"undefined"|"undefined"|"[object Object]""5e3712c6958b2b1896070f2b"|"127342"|"8452063505"|"1"|"1"|"undefined"|"undefined"|"undefined"|"Yes I am looking in the lower to central Florida market. Multi family units."|"1580667590"|"1580667591"|"Daniel "|"Lepore"|"daniellepore@icloud.com"|"undefined"|"undefined"|"undefined"|"undefined"|"undefined"|"[object Object]""5e37107f61befe0bea740cfa"|"127342"|"3867770002"|"1"|"1"|"undefined"|"undefined"|"undefined"|"He's with Habib
His last name is not Thompson that Habib name"|"1580667007"|"1580667007"|"Thompson"|""|""|"undefined"|"undefined"|"undefined"|"undefined"|"undefined"|"[object Object]""5e370e08853f2702e40828fa"|"127342"|"4073712312"|"1"|"1"|"undefined"|"undefined"|"undefined"|"Indeed we are looking for Buy, Fix and Sell and strong rentals including duplexes, triplexes etc.
"|"1580666376"|"1580666376"|"Gisela "|"Escobar"|"jbetfinancial@gmail.com"|"undefined"|"undefined"|"undefined"|"undefined"|"undefined"|"[object Object]""5e3709f351798f62ea228e08"|"127342"|"4077774697"|"1"|"1"|"undefined"|"undefined"|"undefined"|"Yes I am buying in that area or any area in Florida if the numbers are right
only in Flipping houses

The "Note" field is the challenge here. What I run cat --show-all filename, I see the LF "$" character at the end of each record as well as inside the "Note" field.

I tried tr '\n'''<filename but it removes all the LF characters. Is there a way to remove the LF characters only inside the "Note" field?

PS: Raw data file (9 lines) if you want to check for yourself.


Viewing all articles
Browse latest Browse all 142646

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>