I have a CSV with unix line endings, but some of the string values have windows line endings in them:
date,notes\n
2014-01-01,"Blah Blah Blah"\n
2014-01-02,"Two things:\r\n - first thing\r\n - second thing\n
2014-01-03,"Foo"\n
Note that \n and \r just show where the non-printable characters are in the file, it's not how it would look if you opened it in a text editor.
**I want to remove instances of \r\n, but keep the actual line endings, where it's just \n.** The output should look like:
date,notes\n
2014-01-01,"Blah Blah Blah"\n
2014-01-02,"Two things: - first thing - second thing\n
2014-01-03,"Foo"\n
I need something like
tr -d '\r\n' file.csv
but where it deletes the string \r\n
, rather than either \r
or \n
.
If I try to process it with sed
it's treated like so when processing line-by-line, so it doesn't really work:
date,notes
2014-01-01,"Blah Blah Blah"
2014-01-02,"Two things:\r
- first thing\r
- second thing
2014-01-03,"Foo"
Asked by Dean
(551 rep)
Mar 22, 2016, 06:36 PM
Last activity: Apr 23, 2025, 12:48 PM
Last activity: Apr 23, 2025, 12:48 PM