什么是 Miller?
Miller 类似于 awk、sed、cut、join 和 sort,适用于 CSV、TSV、JSON、JSON Lines 以及基于位置索引等数据格式。
Miller 能为我做什么?
使用 Miller,你可以使用命名字段而无需计算位置索引,并采用 CSV、TSV、JSON、JSON Lines 以及基于位置索引等熟悉的格式。然后,你可以即时添加作为现有字段函数的新字段、删除字段、排序、进行统计聚合、美化输出等。

-
Miller 处理的是键值对数据,而熟悉的 Unix 工具处理的是整数索引字段:如果后者的自然数据结构是数组,那么 Miller 的自然数据结构就是 保持插入顺序的哈希映射。
-
Miller 支持多种数据格式, 包括但不限于熟悉的 CSV、TSV 以及 JSON/JSON Lines。 (Miller 也能处理位置索引数据!)
在上面的图片中,你可以看到 Miller 如何拥抱各种数据格式中键值对数据的共同主题。
安装
| 操作系统 | 安装命令 |
|---|---|
| Linux | yum install millerapt-get install millersnap install miller |
| Mac | brew install millerport install miller |
| Windows | choco install millerwinget install Miller.Millerscoop install main/miller |
另请参阅 README-versions.md 以获取完整的软件包版本列表。请注意,长期支持(LtS)版本可能基于较旧的版本。
另请参阅 从源码构建。
特性
-
Miller 是多用途的:它适用于数据清洗、 数据缩减、统计报告、devops、系统 管理、日志文件处理、格式转换 以及 数据库查询后处理。
-
你可以使用 Miller 来抓取和处理日志文件数据,包括 筛选出相关的子流,然后生成 CSV 格式并将其加载到 全内存/数据框工具中,以进行进一步的统计和/或图形 处理。
-
Miller 补充了数据分析工具,例如 R、pandas 等: 你可以使用 Miller 来清理和准备你的数据。虽然你可以完全在 Miller 中执行 基本统计,但其流式数据特性和 单遍算法使你能够缩减非常大的数据集。
-
Miller 补充了 SQL 数据库:你可以在客户端对数据进行切片、切块和重新格式化, 以便将其输入或输出数据库。你还可以在需要快速、无需设置的一次性任务时, 获得数据库的一些好处,当你只是 需要紧急查询磁盘文件中的一些数据时。
-
Miller 还超越了经典的 Unix 工具,完全步入我们 现代的无 SQL世界:其基本的记录异构性属性允许 Miller 操作那些具有不同模式(字段名)的记录 交错的数据。
-
Miller 是流式的:大多数操作每次只需在内存中处理一条记录,而不是在产生任何输出之前先摄取所有输入。 对于需要更深层次保留的操作(
sort、tac、stats1), Miller 仅保留所需的数据量。这意味着只要功能上可行, 你就可以处理比系统’s 可用 RAM 更大的文件,并且可以在 tail -f 上下文中使用 Miller。 -
Miller 是管道友好的,并且与 Unix 工具包互操作。
-
Miller 的 I/O 格式包括表格化美观打印、按位置索引 (Unix 工具包风格)、CSV、TSV、JSON、JSON Lines 等。
-
Miller 在格式之间进行转换。
-
Miller 的处理是格式感知的:例如,CSV
sort和tac会将表头行保持在最前面。 -
Miller 具有与 Unix 工具包相当的高性能吞吐量。
-
Miller 使用可移植的现代 Go 编写,具有零运行时依赖。 你可以下载或编译单个二进制文件,
scp它到远程机器上, 并期望它能正常工作。
入门
- 10 分钟学会 Miller
- 命令行数据操作指南
- Miller 快速教程
- Miller 练习
- 从命令行操作 CSV 文件的工具
- www.togaware.com/linux/survivor/CSV_Files.html
- 用于 CSV 操作的 MLR
- Linux Magazine:使用 Miller 处理结构化文本文件
- Miller:命令行 CSV 文件处理
- Miller - CSV 数据、数据科学和数据清洗的瑞士军刀链锯
- Pandas 杀手:mlr,科学家
更多文档链接
社区
- 讨论论坛: https://github.com/johnkerl/miller/discussions
- 功能请求 / 错误报告: https://github.com/johnkerl/miller/issues
- 如何贡献: https://miller.readthedocs.io/en/latest/contributing/
构建状态
从源码构建
- 首先:
cd /where/you/want/to/put/the/sourcegit clone https://github.com/johnkerl/millercd miller
- 使用
make:- 构建:
make。这只需几秒钟,并生成 Miller 可执行文件,即./mlr(在 Windows 上为.\mlr.exe)。 - 运行测试:
make check。 - 安装:
make install。这将安装可执行文件/usr/local/bin/mlr和手册页/usr/local/share/man/man1/mlr.1(因此你可以执行man mlr)。 - 如果你希望安装到
/usr/local以外的位置,可以在make install之前执行./configure --prefix=/some/install/path。
- 构建:
- 不使用
make:- 构建:
go build github.com/johnkerl/miller/v6/cmd/mlr。 - 运行测试:
go test github.com/johnkerl/miller/v6/pkg/...和mlr regtest。 - 安装:
go install github.com/johnkerl/miller/v6/cmd/mlr@latest将安装到 GOPATH/bin/mlr。
- 构建:
- 另请参阅关于 从源代码构建 的文档页面。
- 有关更多开发者信息,请参阅 README-dev.md。
面向开发者
许可证
人们对 Miller 的评价
Today I discovered Miller—it's like jq but for CSV: https://t.co/pn5Ni241KM
— Adrien Trouillaud (@adrienjt) September 24, 2020
Also, "Miller complements data-analysis tools such as R, pandas, etc.: you can use Miller to clean and prepare your data." @GreatBlueC @nfmcclure
Underappreciated swiss-army command-line chainsaw.
— Dirk Eddelbuettel (@eddelbuettel) February 28, 2017
"Miller is like awk, sed, cut, join, and sort for [...] CSV, TSV, and [...] JSON." https://t.co/TrQqSUK3KK
Miller looks like a great command line tool for working with CSV data. Sed, awk, cut, join all rolled into one: http://t.co/9BBb6VCZ6Y
— Mike Loukides (@mikeloukides) August 16, 2015
Miller is like sed, awk, cut, join, and sort for name-indexed data such as CSV: http://t.co/1zPbfg6B2W - handy tool!
— Ilya Grigorik (@igrigorik) August 22, 2015
顺便说一句,我认为 Miller 是处理 CSV 的最佳 CLI 工具。过去我需要用它来预处理那些大到无法直接加载到 R 中的 CSV 文件(不过现在有了 vroom,这种情况可能很少见了……)https://t.co/kUjrSSGJoT
— Hiroaki Yutani (@yutannihilat_en) April 21, 2020
Miller: a *format-aware* data munging tool By @__jo_ker__ to overcome limitations with *line-aware* workshorses like awk, sed et al https://t.co/LCyPkhYvt9
— Donny Daniel (@dnnydnl) September 9, 2018
The project website is a fantastic example of good software documentation!!
天哪,这个数据瑞士军刀太棒了!为什么之前没人向我推荐 Miller https://t.co/JGQpmRAZLv 来解决数据库清洗 / ETL 问题呢
— James Miller (@japanlawprof) June 12, 2018
恭喜 @__jo_ker__ 开发了这款用于关键数据管理任务的极其直观的工具!#DataScienceandLaw #ComputationalLaw
🤯@__jo_ker__'s Miller 可以轻松读取、转换和写入各种表格数据。它是独立的、快速的,并且专为流式数据而构建(逐行处理,因此可以处理比内存更大的文件)。
— Benjamin Wolfe (he/him) (@BenjaminWolfe) September 9, 2021
而且文档堪称梦想。我整个上午都在阅读它们! https://t.co/Be2pGPZK6t
Contributors ✨
感谢所有帮助让 Miller 变得更好的优秀人士(emoji key):
<td align="center"><a href="https://dsel.net/"><img src="https://avatars.githubusercontent.com/u/921669?v=4?s=50" width="50px;" alt=""/><br /><sub><b>David Selassie</b></sub></a><br /><a href="#ideas-davidselassie" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="http://www.joelparkerhenderson.com/"><img src="https://avatars.githubusercontent.com/u/27145?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Joel Parker Henderson</b></sub></a><br /><a href="#ideas-joelparkerhenderson" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/divtiply"><img src="https://avatars.githubusercontent.com/u/5359679?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Michel Ace</b></sub></a><br /><a href="#ideas-divtiply" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="http://fuco1.github.io/sitemap.html"><img src="https://avatars.githubusercontent.com/u/2664959?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Matus Goljer</b></sub></a><br /><a href="#ideas-Fuco1" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/terorie"><img src="https://avatars.githubusercontent.com/u/21371810?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Richard Patel</b></sub></a><br /><a href="#platform-terorie" title="Packaging/porting to new platform">📦</a></td>
<td align="center"><a href="https://github.com/Andy1978"><img src="https://avatars.githubusercontent.com/u/240064?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Andreas Weber</b></sub></a><br /><a href="#ideas-Andy1978" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/vapniks"><img src="https://avatars.githubusercontent.com/u/174330?v=4?s=50" width="50px;" alt=""/><br /><sub><b>vapniks</b></sub></a><br /><a href="#platform-vapniks" title="Packaging/porting to new platform">📦</a></td>
本项目遵循 all-contributors 规范。欢迎任何形式的贡献!