Parsing errors due to special characters in dns txt records

1

I have trouble parsing dns txt records retrieved by a script I wrote. The script takes a records, ns records and txt records and writes them to a .csv file. I am using semicolon to separate entries and " as text delimiter.

As txt records contain special characters like ", this leads to parsing errors, when I try to open the .csv file in e.g. spreadsheets.

IN TXT "verification=12345678901234567890"

If there are multiple entries per record, this leads to " occur within a record and e.g. "" at the end of entries. Leading to cdn.net."verification=12345678901234567890"";"...

Is there a decent way to prevent such problems inside the script? Using multiple text delimiters seems one solution but also like an ugly hack.

Katja Eichelberger

Posted 2017-11-08T09:16:56.537

Reputation: 111

Tell your spreadsheet application to only split on semicolons, and not on commas? – mtak – 2017-11-08T09:22:12.067

Answers

1

CSV files are simply text files formatted with a delimiter that you might choose. So basically the delimiter is not something that you force in the document you're writing but it's the person that wants to open the file the one that might choose the delimiter. " is just the one by default, but might be changed.

Nowadays any decent software that handles CSV files allows users to choose the delimiter. I'd suggest choose a character that you're sure you won't use as the delimiter of the document (for example: $, #, ...) and tell the people that should open the document that the delimiter is that character instead of ".

Another way is opening the file yourself for the first time with the delimiter you chose and save the file into another format (.xls, for instance) and send this latter file to the people that should read the document. This way they won't need to choose any delimiters on opening.

nKn

Posted 2017-11-08T09:16:56.537

Reputation: 4 960