Is is possible to convert comma-separated value (CSV) to tab-separated value (TSV) via headless mode?

Hi, is it possible to convert csv or xls to tsv format? Specifically in headless mode. I have tried converting using the following:

libreoffice --headless --convert-to tsv “foo.csv”

but the output is garbled and full of unprintable characters.

Thanks for any help

loffice "-env:UserInstallation=file:///tmp/LibO_Conversion" --convert-to csv:"Text - txt - csv (StarCalc)":9,34,UTF8 --headless --outdir some/path --infilter='csv:44,34,UTF8' some.csv works fine on 5.3 for me. Should be reopened and added as an answer IMO, it’s very hard to put this command line together from the available documentation.

A comma/character-separated value (CSV) or delimiter-separated value (DSV) file can use a comma, semi-colon, tab, or any other character, to separate the values. The related output filter is txt:"Text - txt - csv (StarCalc)" (which can also be used as csv:"Text - txt - csv (StarCalc)" and even tsv:"Text - txt - csv (StarCalc)"). Unfortunately though, the headless / convert-to mode for LO is used to convert between formats that LO can read/write rather than adjust an existing format (e.g., CSV from commas to tabs). Even the recent changes made in fdo#36313 (v4.4) to allow specifying of the delimiter and text quotation mark to support UTF-8 encoding (e.g., --infilter=CSV:59,34,UTF8) do not appear to assist in this respect.

Why not simply do a find/replace externally on the file to convert the commas to tabs? Use a regular expression if you have to (to ensure you don’t pick-up data by mistake).

A CSV file is traditionally a Comma, not Character, separated file. Commas were a pretty bad delimiter choice in the first place, and “correcting” this error by allowing any character has made a bad format more ambiguous. There are of course such things as TSV files, which is why Excel supports them for input and output. One of the few annoying things about LibreOffice is that it does so less well, thereby limiting its use within scientific fields which are chuck full of TSV files.

Re. TSV, fair enough. Whitespace of any kind will always make for a poorer choice in delimiter than a visual character. I will edit the question. Perhaps we should all use delimiter-separated value (DSV).