Use numerical ranges to split out certain lines from a file. https://bitbucket.org/robertmassaioli/splitter

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

MIT licensed by Robert Massaioli


Author: Robert Massaioli

Welcome to the splitter program written in Haskell. The purpose of this program is to allow an easy way to extract ranges of lines from text files. Programs like head and tail extract from the beginning and ends of files and programs like cat print out the entire file. But what if you want to extract lines 101-127 in a file? This is the exact problem that splitter was designed to solve and you can do that like this:

splitter 101-127

Features include:

  • Written in Haskell and therefore Cross-Platform
  • Very Efficient / Very Fast
  • Does one job and does it well: in agreement with the Unix Philosophy.

It is my hope that this tool becomes a valuable part of your toolkit and, if it does, then please feel free to send me an email telling me about it.

Example Invocations

Extract a few choice prime lines from a file:

splitter 2,3,5,7,11,13

Semantically all of the arguments are concatenated together using the ',' symbol meaning that the previous line is identical to this one:

splitter 2 3 5 7 11 12

You can extract spans of lines. For example, getting lines ten to twenty and thirty to eighty would be done like so:

splitter 10-20 30-80

You can extract ranges of lines that are bound on only one end. So if you wanted to extract everything from line fourty onwards then you could do the following:

splitter 40-

You can of course perform the reverse operation and get all the lines counting upto and including fourty:

splitter -40

And, if you really want to then you can just get all of the lines in the file:

splitter *    # This is the same as the 'cat' program

And that is all that there is to it. There are a few extra useful options such as the invert range and number lines options that invert the ranges you selected and add original line numbers next to the output. For more information run the help command.

Important All ranges you can select are inclusive, so 10-20 will include lines ten and twenty. In mathematical notation all ranges are square brackets and not round brackets.

Installation Instructions

Install it just like a normal haskell program. Download the source and then just:

cabal install

And make sure that your cabal bin directory is in your environments PATH variable. That is all that there is to it.

If you wish to have a play around with it first before installing it in your cabal/bin directory then you may wish to install it first in a cabal-dev environment.

Command Line Options

You can get these by simply asking for help:

$ splitter -h
Usage: split [options] <input>
  -n      --numbers  include line numbers in final output
  -i      --invert   get the opposite of the lines specified
  -V, -v  --version  print version number
  -H, -h  --help     print this help message

And that is everything that you can currently do with the splitter program.

Used by 1 package:
comments powered byDisqus