q icon indicating copy to clipboard operation
q copied to clipboard

header in file concatenation

Open gmondo opened this issue 7 years ago • 2 comments

Hi, I have lot of csv file without header, so I thought to add an header file but I get something like this:

$ echo f1,f2 > h.csv
$ echo 1,2 > d.csv
$ q -d, -H "select f1,f2 from h.csv+d.csv"
query error: table temp_table_10001 has no column named c1

Do you have some suggestion to avoid this behaviour without cat of files and pipe to q? Many thanks in advance, Giovanni

gmondo avatar Jan 31 '18 21:01 gmondo

I never saw this + syntax, is that a sqlite feature? Anyway, q -d, "select * from h.csv+d.csv" seems to work fine, no need to provide column names explicitly. You can also use q -d, -O "select c1 as f1, c2 as f2 from d.csv" to avoid creating an intermediate header file.

But why don't you want to use cat? Its exactly made fore usecases like that and you don't even need q for it.

bitti avatar Feb 01 '18 08:02 bitti

Thank you bitti for the response. The problem I exposed is simplified: my csv has tens of fields and I would select only a few. Considering that this usage of an header file seems doable by q manual I think that cat and pipe could make less readable a script calling q.

gmondo avatar Feb 01 '18 17:02 gmondo