Skip to content

TSV read/write #4746

@philrz

Description

@philrz

At the time this issue is being opened, Zed it at commit b8e1b18.

A user asked in a community Slack thread:

I would like for the zq command support the TSV-format (Tab-Separated-Values).
This would make it possible to pipe the output from more programs directly to zq for post-processing. For instance if I select a range of cells in Excel and paste it into the terminal I get TSV-data from Excel. Processed with something like pbpaste | zq -Z - on a Mac. Another program that I often use is VisiData that also outputs TSV by default in pipelines.

We reviewed this one as a team and there was agreement that, particularly given the prevalence of these Excel (and Google Sheets) use cases, it would indeed be useful for us to have direct support for this, e.g.:

  1. Explicit -i tsv for TSV input
  2. Supporting TSV via auto-detect, if feasible
  3. -f tsv for TSV output

While waiting for this to be implemented, it should be noted that there is already TSV support on the input side, though it's not the easiest to use. The -csv.delim option added in #4325 allows the specification of any delimiter when reading via -i csv. Unfortunately, it can be kind of a pain to get the tab character past the shell. For instance, given this input data wine.tsv.gz:

$ gzcat wine.tsv.gz 
#	Year	Winery
1	2019	Brutocao
1	2021	Cabana
1	2020	Castoro

With my Bash shell, after I type the first ", I hit Ctrl-v before hitting Tab and then type the second ", and this gets the tab through to zq (though unfortunately this doesn't survive cut & paste into & out of the GitHub Issue, so users will need to manually complete the steps in their own shells to see it working).

$ zq -version
Version: v1.9.0-7-gb8e1b188

$ zq -i csv -csv.delim "	" wine.tsv.gz 
{"#":1.,Year:2019.,Winery:"Brutocao"}
{"#":1.,Year:2021.,Winery:"Cabana"}
{"#":1.,Year:2020.,Winery:"Castoro"}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions