I need to find what type of line break that is used in a csv file, using Mac. I have exported a data set from SPSS (a statistical software) to a CSV-file. This CSV-file will be sent to be run through a register and I need to provide information regarding the file, such as which line break-style that is used in the file.
As I open the CSV-file in TextEdit on my Mac I see no symbols corresponding to line break (does not say rn, r or n. There is simply a new row with no symbol indicating line break. I have not been able to find what’s used as default in SPSS or how to customize this. I tried by running the file through the Terminal-app and Visual studio code (what I had access to) but no symbols indicating line break. Does anyone know how to determine which line break-style that is used in the CSV-file in this case?
2
Answers
You can open the file in Visual Studio using the Binary editor. You will see all characters.
According the RFC 4180,
CRLF
is the standard record delimiter for CSVs, butLF
is also frequently used. Forget aboutCR
-delimited records as that kind of CSV probably doesn’t exist anymore.Here’s a solution that works in most cases:
The problem with the previous approach is that a CSV record can span multiple lines, so encountering a
LF
doesn’t guaranty that you got to the end of the record. A workaround would be to go to the end of the file and check how it is terminated.You can use perl for that: