Files
tldr/pages.zh/common/textql.md

28 lines
1.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# textql
> 对结构化文本(如 CSV 或 TSV 文件)执行 SQL 查询。
> 更多信息:<https://github.com/dinedal/textql>。
- 打印指定 CSV 文件中符合 SQL 查询的行到 `stdout`
`textql -sql "{{SELECT * FROM filename}}" {{path/to/filename.csv}}`
- 查询 TSV 文件:
`textql -dlm=tab -sql "{{SELECT * FROM filename}}" {{path/to/filename.tsv}}`
- 查询带有表头行的文件:
`textql -dlm={{delimiter}} -header -sql "{{SELECT * FROM filename}}" {{path/to/filename.csv}}`
-`stdin` 读取数据:
`cat {{path/to/file}} | textql -sql "{{SELECT * FROM stdin}}"`
- 在指定的公共列上连接两个文件:
`textql -header -sql "SELECT * FROM {{path/to/file1}} JOIN {{file2}} ON {{path/to/file1}}.{{c1}} = {{file2}}.{{c1}} LIMIT {{10}}" -output-header {{path/to/file1.csv}} {{path/to/file2.csv}}`
- 使用输出分隔符和输出表头行格式化输出:
`textql -output-dlm={{delimiter}} -output-header -sql "SELECT {{column}} AS {{alias}} FROM {{filename}}" {{path/to/filename.csv}}`