Miller is like sed, awk, cut, join, and sort for name-indexed data such as CSV
johnkerl.org
johnkerl.org
One could use DBI + DBD::CSV + Perl to build something similar to q, but that's a batteries not included solution.
I've considered the searchability issue when deciding on a name for it, but eventually favored the day-to-day minimum-typing short name over better searchability.
Anyway, you can search for "harelba q" in order to find it if needed.
Harel @harelba
"
- Convert Excel to CSV: in2csv data.xls > data.csv
- Convert JSON to CSV: in2csv data.json > data.csv
- Print column names: csvcut -n data.csv
- Select a subset of columns: csvcut -c column_a,column_c data.csv > new.csv
- Reorder columns: csvcut -c column_c,column_a data.csv > new.csv
- Find rows with matching ells: csvgrep -c phone_number -r 555-555-\d{4}" data.csv > matching.csv
- Convert to JSON: csvjson data.csv > data.json
- Generate summary statistics: csvstat data.csv
- Query with SQL: csvsql --query "select name from data where age > 30" data.csv > old_folks.csv
- Import into PostgreSQL: csvsql --db postgresql:///database --insert data.csv
- Extract data from PostgreSQL:: sql2csv --db postgresql:///database --query "select * from data" > extract.csv
"
see more: http://csvkit.readthedocs.org/en/0.9.1/#
Can anyone recommend an easy way to convert csv to xls on Linux? I know that libreoffice and gnumeric can do it in headless mode, but it seems terrible overkill.
https://github.com/ferkulat/csv2xls
Since you're going flat file to flat file it would be faster for you as no field name edits are required. You just create a csv input step, xls output step and that's it, save and run the transformation and you're done.
I'd be curious to see how `xsv` (written in Rust) compares performance wise to Miller. (I can't compile Miller---I commented on the issue tracker.)
> Thus the absence of in-process multiprocessing is only a slight penalty in this particular application domain — parallelism here is more easily achieved by running multiple single-threaded processes, each handling its own input files, either on a single host or split across multiple hosts.
I disagree. CSV files can be indexed[1] very simply, providing random access. This makes it trivial to split a large CSV file into chunks which can be operated on in parallel. This lifts the burden off the user to do the splitting and merging manually, which can be become quite tedious when you want to do frequency analysis on the fields.
This type of indexing is not usually seen because it requires support from the underlying CSV parser to produce correct byte offsets. But you've written your own parser here in Miller, so you should be able to do something similar to `xsv`. Moreover, random access gets you slicing proportional to the slice. i.e., extract the last 10 records in a 4M row CSV file is instanteous. This opens up other doors too, like potentially faster joining and fast random sampling.
P.S. I love the name. :-)
cat foo.csv | shellql "select f1, count(*) from tbl where f2='thingiwant' group by f1 order by count(*) desc limit 5"
It has some limitations on the formats of CSV that it can take, namely that string fields have to be quoted, but you can see from the code that there's not much to it if you wanted to change that. It'd also be easy enough to take in multiple CSV files, join them together, etc.sqlite's pretty badass.
https://github.com/Chris00/ocaml-csv/blob/master/examples/cs...
It's a pity that the CSV file format is so fragmented. It's all too common that a CSV file written by tool A can't be read by tool B.
Only very few tools do it right. For example, I think the ruby CSV module has a heuristic to automatically detect the "style" of CSV files, which is pretty neat.
Seeing as this was downvoted, I'm just pointing out that bemoaning how the CSV format is fragmented and then using it incorrectly is the precise reason it is fragmented. It wasn't originally meant to be extended in so many ways, so there really isn't room to complain when a library doesn't magically figure out your personal delimiter or qualifier.
https://github.com/pydata/pandas/blob/master/pandas/io/tests...
BEGIN { first=1; second=2; third=3 }
$first > 42 { print $third }
Here, $first means $ applied to the variable first. Since first evaluates to 1, it means $1.Broken CSV handling that doesn't respect quotes is easily done in awk using comma as the field separator.
https://github.com/johnkerl/miller/commit/a1d117d3b299bbf273...
https://github.com/johnkerl/miller/commit/7aead02c71a76fb281...
Also there is one issue closed (thanks epilanthanomai!) and two open. Remaining feedback items on the miller todo.txt.
Thanks all for the initial feedback -- exactly what I was looking for by posting here!
12:58 shephard:c shephard$ make all
ctags -R .
ctags: illegal option -- R
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
make: *** [tags] Error 1
[Edit - No "-R" option for ctags in OS X 10.8.5, or in OpenBSD Current - http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/...Edit2 - Now, it seems to be breaking on lemon not being explicitly called out in the path during a make:
lemon filter_dsl_parse.y
make[1]: lemon: No such file or directory
make[1]: *** [filter_dsl_parse.c] Error 1
make: *** [dsls] Error 2
13:07 shephard:c shephard$
]I suspect most people who do deal with bulk CSV files all the time do as well. I'd be curious about how gracefully it handles large CSV files.
The lack of quoting support kills it for my use case however. I wrote my own tools, starting with csv_cut because cut(1) didn't do quoting.
miller handles large files well. it's fast enough, and doesn't hold entire file contents unless it has to (e.g. sort). so gigabytes of input data are fine.
(2) Many of my columns are free-form text containing commas, carriage returns, new lines, tab, vertical tabs and file separator (0x1c). Occasionally, text is in UCS-2/UTF-16 or uses UTF-8 and foreign characters (a non-trivial quantity of the text I process is in French for example.)
(If you read between the lines here, some columns can contain MLLP-encoded HL7 messages, others contain free-form text and I'm in the medical field.)
It's trivial to create a two hop transformation in Pentaho. The first step reads your data out of a CSV, the second loads it to a table. Pentaho will generate the DDL needed to create the table based on discovered field names and types found in the import step based on data introspection.
Having said that I've often wished for a tool exactly like this that's lighter weight than drill (and doesn't expose my data on a web page like drill does) so I will definitely bookmark this for the next time it's needed. Hopefully it makes it into the Redhat EPEL.
http://aadrake.com/command-line-tools-can-be-235x-faster-tha...
Most CSV analysis is static, not something ongoing with inserts/updates/etc, so using a combination of unix tools to handle the data processing seems like a sufficient solution for many scenarios.
Here are the equivalent commands from the article:
Import-Csv example.csv | Select-Object year, price | Export-Csv -NoTypeInformation example-cut.csv
Import-Csv example.csv | Sort-Object year | Export-Csv -NoTypeInformation example-sorted.csv
Import-Csv example.csv | Where-Object year -eq 1999 | Export-Csv -NoTypeInformation example-filtered.csv
PowerShell can also deal with JSON and XML in much the same way.As cool as miller is, jq is also decidedly cool, but for json. Both claim that they are "like" awk, sed, cut, paste etc, but for $Format, where $Format is csv/tsv and json, respectively.
They both deal with much the same tasks, and there is considerable overlap.
What your PowerShell examples do not say, is how - after Import-Csv - you are no longer constrained to tools written for csv's (or json or ...). At that point the records of the csv file have become objects in the PowerShell type system (which is an extension of the .NET type system).
Another point about the corresponding functionality in PowerShell is how you do not need to convert back to csv, json or whatever. Your Export-Csv commands in your examples are only needed if you want to finally save the results as csv. Otherwise you would just keep the objects in a variable or flowing through the pipeline/script.
So TFAs 2nd example could be written
ipcsv flins.csv | group county -n
If the data had been in json, one would write cat flins.json | convertfrom-json | group county -n
Which also means that data can be export through any cmdlet that exports or converts a stream of objects: Export-Csv, ConvertTo-Csv, ConvertTo-Html, ConvertTo-Json, ConvertTo-Xml, ...https://technet.microsoft.com/en-us/scriptcenter/dd919274.as...
http://www.microsoft.com/en-us/download/details.aspx?id=2465...
It handles around 20 different input formats and is pretty fast. Has a COM API and is extensible. we use it to capture event log data from our windows platform. Has an edge over PowerShell when it comes to speed for certain types of tasks.
Harel
R is specifically designed for manipulating datasets though, and has a lot more functionality/dependencies. If you're already familiar with the language, and okay with the dependencies, it is vastly more powerful, more succinct, and arguably easier to use. Otherwise, something in between probably still makes sense.