11 ms·
XSV: A fast CSV command-line toolkit written in Rust
- tajen 8y agoXML-separated values? Fortunately no: command line program for indexing, slicing, analyzing, splitting and joining CSV files.
- ubernostrum 8y agoThis comment shouldn't have been downvoted/killed; at the time it was made, the title of the post was completely uninformative, leaving people to guess what on earth "XSV" might be.
- watmough 8y agoXML-separated values? It sounds like some kind of (easily detected) side-band, or an xkcd cartoon.
- deleted 8y ago[deleted]
- cube2222 8y agoI like how all those rust/go implemented, fast, cross-platform tools are starting to get mainstream. (ripgrep's another great one). Really useful if you're a programmer preferring Windows but mainly using Unix tools and developing for Unix OSes. By the way, I've been using xsv when analysing 8 GB csv's (the Amazon review dataset) and have been nothing but happy with it.
- da_chicken 8y agoI'd be curious how it stacks up against Microsoft's LogParser[0]. [0]: https://en.wikipedia.org/wiki/Logparser https://en.wikipedia.org/wiki/Logparser
- et2o 8y agoRipgrep is by the same author, actually.
- cube2222 8y agoYup, I know. Actually, the official regexp implementation in rust (underlying ripgrep) is written by him, too.
- vram22 8y ago>I like how all those rust/go implemented, fast, cross-platform tools are starting to get mainstream. (ripgrep's another great one). Both xsv and ripgrep are by BurntSushi, and ripgrep was mentioned twice on HN recently, once in a release note thread, IIRC, and another time in the CLI: Improved thread. Both were mentioned before too.
- thsowers 8y agoHadn't heard of rg before, awesome! Perfect counterpart to sharkdp's alternative find: https://github.com/sharkdp/fd https://github.com/sharkdp/fd
- adamnemecek 8y agoBurntsushi is like the most productive programmer.
- person_of_color 8y agoBurntSushi will soon be BurntOut ;)
- domoritz 8y agoThis is great. For now, my go to tool is csvkit (Python) which has all kinds of neat tools. In particular loading data into databases (csvsql) is just plain awesome. Check it out at https://csvkit.readthedocs.io/en/1.0.3/ https://csvkit.readthedocs.io/en/1.0.3/.
- convivialdingo 8y agoReally nice! I think I’ve written at least a couple of these in some basic form myself. At some point in a business someone is going to hand you CSV or excel dataset and you end up having to deal with it.
- colanderman 8y agoOK, dumb question, because there have been a LOT of these types of stories lately: Why does it matter (beside to the implementor, or for pedagogy) what language a CLI tool is implemented in?
- cube2222 8y agoRust and Go are languages with ecosystems, in which writing everything in a cross-platform way is the default. They also compile to a single statically linked binary. You don't need an additional runtime + load of dependencies like node or python. They are lightweight and fast to start up as opposed to the jvm.
- shawn 8y agoPython is installed literally everywhere. If it’s a CLI tool, and it’s written in python, the chance that it won’t work is slim. Go has a massive number of problems. For example, I tried to run Keybase’s standard “go get” build instructions. It failed with 200 import errors. That was the end of my attempt to install keybase on my raspberry pi. Others had said that it works. Rust requires a massive amount of hard drive space and takes a long time to build. You also have to build it. That’s antithetical to rapid development. I can't wait until the pendulum swings back away from static typing and the next generation of programmers discover the benefits of literally ignoring everybody and doing your own thing. It’ll be painful, but at least it’ll be effective. And you won’t have to compile anything.
- rookwood102 8y agoBurntsushi mentions in the readme that it is often the case that people receive large csv files needing analysis but he also mentions that valid criticisms of the tool are that you could use an SQL database. Why can't you use a database in some scenarios? And when blazing in memory speed is useful, why can't you use something like this: https://github.com/jtablesaw/tablesaw https://github.com/jtablesaw/tablesaw Is XSV faster? Is it the command line convenience (although surely it was not that convenient to write a new tool to do it) Genuinely curious and I do not mean to belittle the project as it looks well implemented and useful nonetheless.
- Ecco 8y agoSeems great at first, but how is that better than piping the whole CSV file into SQLite and then doing the processing there? I think CSV is great for data exchange but not so great for data processing. By using SQLite (or any other DB actually) you can decide which data to index, and write arbitrarily complex queries in a rather understandable language. I think XSV is kind of reinventing the wheel here.
- burntsushi 8y agoYou could. But then you need to write a schema. How do you know what schema to write? You could ask csvkit to do it, but it might not be fast enough on, say, a 40GB CSV file. Or maybe it isn't quite accurate enough. xsv might be the tool you use to figure out what the schema should be. SQLite (or any SQL database) does not cover all use cases. For example, if you need to produce CSV data, and you can fit your transformation into xsv commands, then it might be hard to beat the performance in exchange for the effort you put in. This is probably an expression problem. Tools don't always neatly fit into orthogonal buckets. If you think in terms of shell pipelines and want to attack the data as it is, then xsv might be good for you. SQLite is, IMO, a pretty massive hammer to apply every single time you want to look at CSV data.
- Ecco 8y agoFor non-lookup csv-to-csv transformation, yes, I guess your tool can easily beat any SQL DB since it can work without any need for an external storage. That also applies to sequential-scan queries too. You make a good point :-) Regarding the schema now, I’m not sure I get your point. I would argue the queries you want to make already dictate a schema (e.g. you want to compute an average ? Use a numeric column).
- burntsushi 8y ago> Regarding the schema now, I’m not sure I get your point. I would argue the queries you want to make already dictate a schema (e.g. you want to compute an average ? Use a numeric column). Yeah that's fine. I think we're just missing each other, that's all. I'm not sure what kind of CSV data you've worked with, but from the stuff I've seen, it's rarely clean. `xsv frequency` and `xsv stats` are great ways to look at your data as it is. For example, a column might be named as if it were a numeric field. Maybe it's first hundred rows are even numeric. But there might be a row where it isn't numeric and isn't even empty, but has some kind of weird value in it. Like, say, 'N/A' or 'null' or 'none' or whatever sentinel value someone decided to use to indicate absence. Data types can be richer than just primitives too. For example, one field might be an enumeration of a fixed set of values, and I can think of at least three different ways you might want to represent that in your schema.
- go_prodev 8y agoThis looks great, and I'm very keen to try it out. I have a malformed 115GB CSV which took some work to process with SSIS, but I'm really interested to try again using xsv to split off the bad rows and see if that would have been an easier option. Very cool!
- mastrsushi 8y agoI started to write a similar application in C++. Have up because I didn't think people would find it useful. After seeing this in the front page, I feel it might be a good idea to get back in. https://github.com/tfili001/line https://github.com/tfili001/line If I get back into this, CSV parsing will be my next step.
- burntsushi 8y agoCheck out csvmonkey for a really fast C++ csv parser: https://github.com/dw/csvmonkey https://github.com/dw/csvmonkey
- sunpazed 8y agoHave been using xsv (in combination with any-json, and jq) for a few months wrangling big csv files at work. Found it to be a better / faster process than rolling my own code.
- gregw2 8y agono CSV diff capability? find which columns are different, which rows? ability to ignore spaces or leading/trailing 0s or quote marks?
- burntsushi 8y agoI imagine you could get pretty far with diff <(xsv input old.csv) <(xsv input new.csv) In particular, xsv prints valid CSV, and quoting rules will be applied consistently so that they can be diffed. Ignoring spaces and 0s might not work though. If you'd like to file an issue with a specific use case (sample data from a real world problem would be great), then that would be appreciated!
- deleted 8y ago[deleted]
- jancsika 8y agoOk, I'm curious and may have follow-ups: What exactly is being checksummed in cargo.lock? Is it the source code, a binary, something else?
- e12e 8y agohttps://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lo...
- dbaupp 8y agoThat doesn't seem to talk about the series of "checksum ..." entries in the [metadata] section at the end of the Cargo.lock.
- e12e 8y agoHm, appears to be an alternate (new? Old?) syntax for: "Cargo will take the latest commit and write that information out into our Cargo.lock when we build for the first time. That file will look like this: [[package]] name = "hello_world" version = "0.1.0" dependencies = [ "rand 0.1.0 (git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9)" https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeed..., ] [[package]] name = "rand" version = "0.1.0" source = "git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9" https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeed... You can see that there’s a lot more information here, including the exact revision we used to build."
- dbaupp 8y agoNo, the git hashes are still there in the same syntax as described in that document. In fact, the checksum entry of a git dependency seems to be "<none>".
- lerax 8y agoAwesome tool. Pretty useful to manage big-scary csv files.
- deleted 8y ago[deleted]
- damageboy 8y agoWould be interesting to see how xsv compared to miller (https://johnkerl.org/miller/doc/index.html https://johnkerl.org/miller/doc/index.html) in terms of perf, this tool comes exactly as I am about to munge 1TB of gzipped csv files. Unfortunately, the main operation I need is not supported by xsv...
- notimetorelax 8y agoWhat is the operation that you need? Can you send a PR?
- fithisux 8y agoI have used the simple and beautiful tool https://github.com/Clever/csvlint https://github.com/Clever/csvlint It is in golang.
- tigrezno 8y agoWhat about using awk?
- burntsushi 8y agoawk doesn't support csv.
- safgasCVS 8y agoThank you for this! I've been looking for windows equivalent to csvkit and this is just the ticket
- kunashe 8y agoBurntSushi, dude you're awesome.
- adiusmus 8y agoGood to have another tool for csv debris management. Especially those multigigabyte gifts that need to be in the database “yesterday”. This has happened several days or weeks in a row more times than I can count. And no, people won’t provide such things in sqlite or something sane. I feel like I should also recommend this: https://digital-preservation.github.io/csv-validator/ https://digital-preservation.github.io/csv-validator/ I think something like this rewritten in go would be great.
- burntsushi 8y ago> I think something like this rewritten in go would be great. Why not use it how it is? There are static binaries provided on github.
- dj43nq 8y agoIsn’t that Java? Not everyone wants java on their server, I’d like something in c or rust. Good project for a few weekends work.
- miguelmota 8y agoBurntSushi is a badass; always cranking out awesome tools. I use ripgrep [1] on a daily basis as a grep replacement [1] https://github.com/BurntSushi/ripgrep https://github.com/BurntSushi/ripgrep
- bpicolo 8y agoTheir FST library is also awesome https://github.com/BurntSushi/fst https://github.com/BurntSushi/fst
- Dowwie 8y agoI like the pager UI of the VisiData utility, written in Python, for exploring data. Since XSV is written in Rust, it could theoretically be imported and used in VisiData. https://github.com/saulpw/visidata https://github.com/saulpw/visidata
- radarsat1 8y agoI'm not too familiar with rust tools, but I wanted to check this out. Can someone explain to me why this worked, sudo apt-get install cargo rustc cargo install xsv but this did not: git clone <xsv github> cd xsv cargo build --release The latter gave me a ton of compilation errors on the package crossbeam-channel. The former installed the program and compiled a bunch of crates, but did it install a pre-built binary for xsv? "downloading" then "installing" of xsv was the first step, then all the crates were downloaded. ldd seems to report that the installed xsv binary has no dependencies so I don't see why it would need to download and compile a bunch of crates in that case. On the other hand if it was compiling xsv then I don't understand why I don't get the same errors as in the latter case. It seems Ubuntu has the following version: $ rustc --version rustc 1.25.0 I realize it's probably not optimal to use the Debian-packaged rustc but I didn't feel like figuring out the whole ecosystem just to install one program to test it out.
- burntsushi 8y agoBecause current master requires a newer version of the Rust compiler than the current release on crates.io. If current master were a release, then `cargo install xsv` would have failed with the same errors. If you like, you can download static binaries from github: https://github.com/BurntSushi/xsv/releases https://github.com/BurntSushi/xsv/releases
- radarsat1 8y agoAh, ok thanks. Anyways I got it installed, was just wondering about certain actions that cargo took. I found I could copy the resulting binary and delete my entire .cargo directory and it continues to work, so it seems cargo did some unnecessary things for `install`, but no worries.
- burntsushi 8y agoTo add to this: Cargo is more of a development tool for Rust programmers rather than a package manager for end users. Both types of tools have a lot in common, which is why things like `cargo install` exist and are very useful. In the case of `xsv`, it's a useful escape hatch since your distro doesn't package `xsv`, but `cargo install` is not like `apt install`. That is, it downloads all of the source code dependencies of `xsv` and builds them. This also requires sync'ing with crates.io's registry list. None of this is unnecessary in the standard Cargo workflow in order to build xsv, but the build artifacts are certainly unnecessary in order to run xsv.
- alexey454545 8y agoHello everyone, I’m the most happiest person on the face of the earth, after 6 months of sadness and sorrow without being with the one i love, i tried all my possible best to make sure i make my lover happy but it never seems to work out well it was like am doing everything in vain but all thanks goes to Dr Asaka for coming to change all my worries and sadness to happiness. i knew the great man when i read some wonderful testimony about how he has helped lots of people on their relationship problems. i was reading a magazine when i saw great testimonies, as well my predicament then i decided not to waste time because i have missed my lover so much i decided to contact him and share all my problem with him which he told me not to worry that he is assuring me that within 48 hours everything would be sorted out i believed Dr Asaka so much because of how he has been helping many people, my boyfriend who left me for good suddenly replied my text and returned my calls and asked me to please forgive him i was so happy am so grateful to Dr Asaka for what he has done for me and I promise to testify his goodness all through my life. If you are there passing through the same problem or any kinds of problem contact this great man on his email address: drasakaspelltemple@gmail.com
- rixed 8y agoAlso relevant, this forgotten gem: http://www.rseventeen.com/ http://www.rseventeen.com/