TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Miller CLI – Like Awk, sed, cut, join, and sort for CSV, TSV and JSON

273 pointsby jaboover 3 years ago

25 comments

yung_steezyover 3 years ago
I always use sqlite3 for working with large CSV files:<p><pre><code> $ sqlite3 $ .mode csv $ .import my.csv foo $ SELECT * FROM foo WHERE name = &#x27;bar&#x27;; </code></pre> It reads the header in automatically for the field names and then stores all the values as strings.
评论 #28302499 未加载
评论 #28302364 未加载
评论 #28300871 未加载
评论 #28303106 未加载
评论 #28301369 未加载
评论 #28300068 未加载
评论 #28299927 未加载
brushfootover 3 years ago
If you have Windows, you have a tool that can do this already installed: PowerShell. (If you don&#x27;t have Windows, PowerShell is free and open source [MIT license]. One of the first things I install on a new Linux or macOS box lately.)<p>The first example in PowerShell:<p>&gt; Import-Csv example.csv | Sort-Object Color, Shape<p>To filter, use `Where-Object`:<p>&gt; Import-Csv example.csv | Where-Object { $_.Color -eq &#x27;purple&#x27; } | Sort-Object Color, Shape<p>Or using aliases:<p>&gt; ipcsv example.csv | ? { $_.Color -eq &#x27;purple&#x27; } | sort Color, Shape<p>JSON uses the same syntax -- just replace `Import-Csv` with `Get-Content` and `ConvertFrom-Json`:<p>&gt; Get-Content example.json | ConvertFrom-Json | Select-Object Color -Unique<p>&gt; purple<p>&gt; red<p>&gt; yellow<p>There&#x27;s also `Group-Object` for aggregation.
msluyterover 3 years ago
Some other useful tools for csv files, in particular:<p>csvkit, a set of command line tools for manipulating csvs: <a href="https:&#x2F;&#x2F;csvkit.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;csvkit.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a><p>visdata, a quite terminal based csv explorer: <a href="https:&#x2F;&#x2F;www.visidata.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.visidata.org&#x2F;</a>
评论 #28307285 未加载
awildover 3 years ago
I make a lot of use of Miller at work and it has been a godsend. People tend to underestimate tools like this, but I&#x27;m able to answer a lot of questions about our data that other people would take longer for or don&#x27;t have the capacity to check. It&#x27;s great as a first step and if anything more complex is needed we usually spin up a python script. So it&#x27;s very much in the philosophy of small composable tools but for records.
citilifeover 3 years ago
Not exactly the same, but we wrote a library to easily load any delimited type of file and finds header (even if not first row). It also works to load JSON, Parquet, AVRO and loads it into a dataframe. Not CLI exactly, but pretty easy:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;capitalone&#x2F;dataprofiler" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;capitalone&#x2F;dataprofiler</a><p>Can Install: <i>pip install dataprofiler[ml] --user</i><p>How it works:<p>csv_data = Data(&#x27;your_file.csv&#x27;) # Load: delimited, JSON, Parquet, Avro<p>csv_data.data.head(10) # Get head<p>csv_data.data.sort_values(by=&#x27;name&#x27;, inplace=True) # Sort<p>Anyway, pretty interesting Miller CLI. I&#x27;m not sure how the header detection works, especially if the header isn&#x27;t the first row (which is often the case)
评论 #28304497 未加载
traceroute66over 3 years ago
Is this (supposedly) better than Burntsushi toolset (e.g. XSV[1]) or just different ?<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;xsv" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;xsv</a>
评论 #28300289 未加载
flakinessover 3 years ago
The comparison between their ongoing C version [1] and the upcoming go version [2] is nice to see. The README talks a bit more the performance comparison and the C version&#x27;s strength, but still.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;johnkerl&#x2F;miller&#x2F;tree&#x2F;main&#x2F;c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;johnkerl&#x2F;miller&#x2F;tree&#x2F;main&#x2F;c</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;johnkerl&#x2F;miller&#x2F;tree&#x2F;main&#x2F;go" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;johnkerl&#x2F;miller&#x2F;tree&#x2F;main&#x2F;go</a>
otabdeveloper4over 3 years ago
See also my own foray into this space: <a href="https:&#x2F;&#x2F;tkatchev.bitbucket.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tkatchev.bitbucket.io&#x2F;</a><p>You might find it useful.
评论 #28299819 未加载
chrisweeklyover 3 years ago
See LNAV (<a href="https:&#x2F;&#x2F;lnav.org" rel="nofollow">https:&#x2F;&#x2F;lnav.org</a>) for a &quot;mini-ETL&quot; CLI powertool with embedded SQLite; it&#x27;s fantastic.
sam_goodyover 3 years ago
How does this compare to JQ?<p>Aside for that it appears to support more formats (CSV [which has partial JQ support], and TSV), of course.<p>I find it very helpful when people compare their new toy or service with what is already pretty well known.
评论 #28302968 未加载
mmahemoffover 3 years ago
I don&#x27;t think Sed and Awk should be on this list. It&#x27;s not really able to transform text into something else, is it?<p>Even the tutorial leans on sed for cleansing ahead of Miller. <a href="https:&#x2F;&#x2F;www.ict4g.net&#x2F;adolfo&#x2F;notes&#x2F;data-analysis&#x2F;miller-quick-tutorial.html" rel="nofollow">https:&#x2F;&#x2F;www.ict4g.net&#x2F;adolfo&#x2F;notes&#x2F;data-analysis&#x2F;miller-quic...</a>
评论 #28302619 未加载
calvinmorrisonover 3 years ago
Just yesterday I was opining in the IRC about what it would be like to have a operating system that was build from the ground up that supports smarter data formats than just text.<p>The concept of everything as a file, has awesome benefits I believe, but that doesn&#x27;t meant files need to be unstructured text.<p>There&#x27;s a core problem, that with text languages (like AWK or structured regex (sed, etc) you end up both having to parse AND manipulate data. which is no fun and prone to errors.<p>Abstracting away all of that into codecs that all of coreutils could speak would be very cool to me.<p>The second issue is structured data vs unstructured text. CSVs, or other table based formats make sense sometimes, and sometimes you want to be able to query things more easily. JSON provides that. What&#x27;s the synthesis of both I don&#x27;t know... but maybe this is closer to heaven.<p>I&#x27;d like to _minimize_ the amount of parsing or text manipulation done in any program and be able to focus on extracting and inserting the data I need, like a rosetta stone that just handles everything for me while I work. I want to be able to do:<p>awk &quot;{print $schoolName}&quot; or awk &quot;{print $4}&quot; and it just works - json, text, CSV.
评论 #28303906 未加载
评论 #28306495 未加载
评论 #28301692 未加载
评论 #28301956 未加载
dima55over 3 years ago
Similar, but using the ACTUAL awk, sed, join, sort tools you already have and know about: <a href="https:&#x2F;&#x2F;github.com&#x2F;dkogan&#x2F;vnlog&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dkogan&#x2F;vnlog&#x2F;</a>
enriqutoover 3 years ago
I&#x27;m a bit surprised by the need of verbose &quot;--icsv --ocsv&quot;... Shouldn&#x27;t it be trivial to see that the input is csv? (and in that case, the output could be csv by default).
评论 #28299139 未加载
评论 #28299082 未加载
throw0101aover 3 years ago
&gt; <i>Like Awk, sed, cut, join, and sort</i> […]<p>So basically Perl? :)
simonwover 3 years ago
I added a new feature to my sqlite-utils CLI tool in June which covers similar ground: it now lets you load CSV, TSV and JSON data into an in-memory SQLite database and execute SQL queries against it: <a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2021&#x2F;Jun&#x2F;19&#x2F;sqlite-utils-memory&#x2F;" rel="nofollow">https:&#x2F;&#x2F;simonwillison.net&#x2F;2021&#x2F;Jun&#x2F;19&#x2F;sqlite-utils-memory&#x2F;</a><p>Example usage:<p><pre><code> sqlite-utils memory example.csv &quot;select * from t order by color, shape&quot; # Defaults to outputting JSON, you can add # --csv or --tsv for those formats or # --table to output as a rendered table </code></pre> More docs here: <a href="https:&#x2F;&#x2F;sqlite-utils.datasette.io&#x2F;en&#x2F;stable&#x2F;cli.html#querying-data-directly-using-an-in-memory-database" rel="nofollow">https:&#x2F;&#x2F;sqlite-utils.datasette.io&#x2F;en&#x2F;stable&#x2F;cli.html#queryin...</a>
xvilkaover 3 years ago
There&#x27;s also rq (record query)[1] that also supports CSV and JSON but not TSV though. It&#x27;s written in Rust.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;dflemstr&#x2F;rq" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dflemstr&#x2F;rq</a>
lenkiteover 3 years ago
I just prefer using R data-frames - the convenience of a full data-science language shell for getting statistical data out of CSV. One can also make gorgeous graphs using ggplot2.
smashahover 3 years ago
Nice. Any reason why installation section is not prominent and on the top of the readme?<p>It&#x27;s even in an non-intuitive place in the documentation.
csmarshallover 3 years ago
I don&#x27;t know about MillerCLI&#x27;s portability, but RecordStream (<a href="https:&#x2F;&#x2F;github.com&#x2F;benbernard&#x2F;RecordStream" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;benbernard&#x2F;RecordStream</a>) is my go to swiss army knife.
muad_kyrlachover 3 years ago
Got a csv or json you need to eff-with from the command line? It&#x27;s Miller time, baby!
nyolfenover 3 years ago
i recently came across jq, which i use for json parsing: <a href="https:&#x2F;&#x2F;stedolan.github.io&#x2F;jq&#x2F;" rel="nofollow">https:&#x2F;&#x2F;stedolan.github.io&#x2F;jq&#x2F;</a>
lazyeyeover 3 years ago
For windows users NimbleText is a great little utility for working with tabular data:-<p><a href="https:&#x2F;&#x2F;nimbletext.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nimbletext.com&#x2F;</a>
nyolfenover 3 years ago
i recently came across `jq`, which i use for this purpose
nwmcsweenover 3 years ago
A bit OT but there really need to be a new paradigm shift for a new OS interface that has less coupling and more flexibility compared to piping.