1

I want to programmatically generate tsv files with multi-line cells that stay preserved when opened in Numbers app.

What newline character to use to enable multi-line cells?

2
  • 1
    To your deleted answer (which wasn't an answer) try this in Terminal: printf '"line one\nline two"\r\nanother line' > foobar.csv Commented Sep 24, 2020 at 23:13
  • @user3439894: Yes this works! Commented Sep 25, 2020 at 5:24

1 Answer 1

1

CSV is kind of standardized with RFC 4180. For multi-line fields the rules are

  • MS-DOS-style lines that end with (CR/LF) characters (optional for the last line).
  • Any field may be quoted (with double quotes).
  • Fields containing a line-break, double-quote or commas should be quoted.
  • If double-quotes are used to enclose fields, then a double-quote must be represented by two double-quote characters.

If this doesn't work with Numbers, you can also create a Numbers file, add some multi-line fields, export the file as CSV/TSV and verify the encoding/quoting used with TextEdit afterwards.

From the comment of @user3439894:

When Numbers exports to CSV it uses CR/LF between rows but uses LF for multi-line cells and the value is in double-quotes.

3
  • When Numbers exports to CSV it uses CR/LF between rows but uses LF for multi-line cells and the value is in double-quotes. Commented Sep 24, 2020 at 7:22
  • @user3439894 Thanks, I've added this to the answer.
    – nohillside
    Commented Sep 24, 2020 at 8:05
  • @nohillside: Works! For anyone trying please make sure there is no space between delimiter and double-quotes. Commented Sep 24, 2020 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .