890 B
890 B
q
在CSV和TSV文件上执行类似SQL的查询。 更多信息:https://harelba.github.io/q。
- 通过指定分隔符为','查询CSV文件:
q -d',' "SELECT * from {{path/to/file}}"
- 查询TSV文件:
q -t "SELECT * from {{path/to/file}}"
- 查询带有表头行的文件:
q -d{{delimiter}} -H "SELECT * from {{path/to/file}}"
- 从
stdin
读取数据;查询中的'-'代表来自stdin
的数据:
{{output}} | q "select * from -"
- 在列
c1
(一个公共列)上连接两个文件(在示例中别名为f1
和f2
):
q "SELECT * FROM {{path/to/file}} f1 JOIN {{path/to/other_file}} f2 ON (f1.c1 = f2.c1)"
- 使用输出分隔符和输出表头行格式化输出(注意:命令将根据输入文件的表头或在查询中重写的列别名输出列名):
q -D{{delimiter}} -O "SELECT {{column}} as {{alias}} from {{path/to/file}}"