I was trying to dig through some log files the other day which aren’t log-rotated with any regularity and so were of a size that would have made a viewer choke on them had I tried to open them. After a little digging I came across the Unix tool ’split’ which did exactly what I wanted it to, take a file and chunk it up into smaller files based on some criteria you provide. Well, after diddling with it for a bit I was unhappy with some things, notably the output names and that there doesn’t seem to be a way to tell it “split on some number of lines, but not if you’re in the middle of a paragraph” so errors to my logs (with their stack traces) were often getting cut off. After a little noodling on the problem I wrote this quick script that will do the same thing as split but with additional features.
1. Go grab the file here: splitr
2. Copy splitr into whatever directory on your system contains executables (I don’t remember what it is for Windows, but for OS X put it in /usr/bin)
3. Make it executable (chmod a+x on OS X or *nix)
4. Start splitting files.