The haskell-awk package

[Tags:apache, library, program, test]

Hawk is a command line utility to process streams of text using Haskell code. It is intended to be used in a UNIX pipeline. It offers a configuration system to personalize imported modules and a way to represent values on the console.

[Skip to Readme]


Versions 1.0, 1.0.1, 1.1, 1.1.1 (info)
Change log
Dependencies base (>= && <5), bytestring, containers, directory, easy-file, exceptions (>=0.1), filepath, haskell-awk, haskell-src-exts (>=1.16.0), hint (>=, mtl (>=2.1.2), network (>=, process, stringsearch (>=, time, transformers (>= [details]
License Apache-2.0
Author Mario Pastorelli <>, Samuel Gélineau <>
Maintainer Mario Pastorelli <>, Samuel Gélineau <>
Category Console
Source repository head: git clone
Uploaded Mon Jul 6 13:13:26 UTC 2015 by gelisam
Distributions NixOS:1.1.1
Downloads 1127 total (7 in the last 30 days)
0 []
Status Docs uploaded by user
Build status unknown [no reports yet]
Hackage Matrix CI




Maintainer's Corner

For package maintainers and hackage trustees

Readme for haskell-awk

Readme for haskell-awk-1.1.1


Transform text from the command-line using Haskell expressions. Similar to awk, but using Haskell as the text-processing language.


In Unix the file /etc/passwd is used to keep track of every registered user in the system. Each entry in the file contains information about a single user, using a simple colon-separated format. For example:


The first field is the username. We can use Hawk to list all usernames as follows:

> cat /etc/passwd | hawk -d: -m 'head'

The -d option tells Hawk to use : as field delimiters, causing the first line to be interpreted as ["root", "x", "0", "0", "root", "/root", "/bin/bash"]. The -m tells Hawk to map a function over each line of the input. In this case, the function head extracts the first field of the line, which happens to be the username.

We could of course have achieved identical results by using awk instead of Hawk:

> cat /etc/passwd | awk -F: '{print $1}'

While Hawk and awk have similar use cases, the philosophy behind the two is very different. Awk uses a specialized language designed to concisely express many text transformations, while Hawk uses the general-purpose language Haskell, which is also known for being concise, among other things. There are many standard command-line tools that can be easily approximated using short Haskell expressions.

Another important difference is that while awk one-liners are self-contained, Hawk encourages the use of libraries and user-defined functions. By adding function definitions, module imports and language pragmas to Hawk's user-configurable prelude file, those functions, libraries and language extensions become available to Hawk one-liners. For instance, we could add a takeLast function extracting the last n elements from a list, and use it to (inefficiently) approximate tail:

> echo 'takeLast n = reverse . take n . reverse' >> ~/.hawk/prelude.hs
> seq 0 100 | hawk -a 'takeLast 3'

For more details, see the documentation.


To install the stable version, simply use cabal install haskell-awk (not cabal install hawk, that's another unrelated package) and add ~/.cabal/bin (or your sandbox's bin folder) to your PATH. You should be ready to use Hawk:

> hawk '[1..3]'

To install the development version, clone this repository and use cabal install or cabal-dev install to compile Hawk and its dependencies. Cabal installs the binary to ~/.cabal/bin/hawk, while cabal-dev installs it to ./cabal-dev/bin/hawk. The first run will create a default configuration into ~/.hawk/prelude.hs if it doesn't exist.

Build Status