• Stars
    star
    361
  • Rank 117,957 (Top 3 %)
  • Language
    Haskell
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Haskell text processor for the command-line

Hawk Hackage Build Status

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

Examples

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:

root:x:0:0:root:/root:/bin/bash

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

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

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}'
root

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'
98
99
100

For more details, see the presentation and the documentation.

Installation

To install hawk, either run stack install haskell-awk or cabal install haskell-awk.

You should be ready to use Hawk:

> hawk '[1..3]'
1
2
3

The first run will create a default configuration file into ~/.hawk/prelude.hs if it doesn't exist.

Alternatives

You can also try hwk which is fairly similar to this project though simpler.

More Repositories

1

frp-zoo

Comparing many FRP implementations by reimplementing the same toy app in each.
Haskell
490
star
2

git-slides

Text-based slides using vim and git.
Shell
152
star
3

klister

an implementation of stuck macros
Haskell
129
star
4

category-syntax

do-notation for Category and "Arrow without arr"
Haskell
63
star
5

typelevel-rewrite-rules

rewrite rules for type-level equalities
Haskell
62
star
6

linear-examples

Example uses of linear types
Haskell
42
star
7

n-ary-functor

A single typeclass for Functor, Bifunctor, Trifunctor, etc.
Haskell
40
star
8

conway

Demonstrating comonad transformers.
Haskell
35
star
9

hyzzy

A framework for defining text adventures via Haskell files. Play by combining functions, not by guessing phrases.
Haskell
32
star
10

ludum-dare-31

The theme for LD31 was "Entire Game on One Screen"
Haskell
29
star
11

magic-typelevel-elem

Demonstrating how to make type families faster using typechecker plugins
Haskell
21
star
12

cabal-rangefinder

A tool to fill in the version ranges in a cabal file.
Haskell
17
star
13

mastering-haskell

The slides for my Packt course, "Mastering Haskell".
Shell
15
star
14

commutative

Using Haskell's type system to guarantee commutativity.
Haskell
15
star
15

typechecker-combinators

Haskell
15
star
16

laughable

Clowns to the left of me, jokers to the right
Haskell
13
star
17

deploy-hint

Demonstrating that you don't need to install ghc in order to use the hint library.
Haskell
11
star
18

surjective

An output coverage checker
Haskell
11
star
19

giggles-is-you

A reimplementation of Baba is You in Haskell, for our weekly haskell-beginners presentations.
Haskell
9
star
20

strongly-typed-bound

My version of Kmett's "strongly typed bound for acowley" snippet.
Haskell
9
star
21

circular-sig

a twelf-like type-checker supporting recursive signatures
Haskell
8
star
22

objc2java

Convert pure ObjectiveC code to pure Java code, libraries be damned.
Haskell
8
star
23

ludum-dare-35

The theme for LD35 was: "shapeshift"
Elm
8
star
24

nominalize

Generate types using type-generic programming, retaining control over the names of the constructors and the fields.
Haskell
6
star
25

image-watcher

Display an image and update it when the file changes
Haskell
6
star
26

ludum-dare-34

The themes for LD34 were: "two button controls" and "growing"
JavaScript
6
star
27

apecs-hint-demo

demonstrating how to use hint to dynamically modify the game world of an apecs-based game
Haskell
5
star
28

slides

A place to host my git-slides presentations
5
star
29

stm-variants

The STM API we know and love, but useable in more circumstances
Haskell
5
star
30

acme-tiny-rules

a parody of Tiny Glade with inference rules instead of castles
Haskell
5
star
31

dot-utils

A set of small command-line tools for transforming GraphViz dot-files
Haskell
4
star
32

k-playground

for implementing toy languages using the K Framework
Haskell
4
star
33

acme-circular-containers

Spineless containers which are fast to read but inefficient to update
Haskell
4
star
34

jira-dependencies

from JIRA's .csv export to graphviz's dot format
Haskell
4
star
35

tarjan

an agda implementation of Tarjan's strongly connected components algorithm
Agda
3
star
36

chopt-test-task

Haskell
3
star
37

worldly

based on Conor McBride's "Worldly Type Systems" talk
Haskell
3
star
38

ludum-dare-44

The theme for LD44 was "Your life is currency"
Rust
3
star
39

agda-playground

a series of ambitious experiments in the functional language / proof assistant Agda.
Vim Script
3
star
40

transliterator

Haskell
3
star
41

premonoidal

Agda encoding of premonoidal categories
Agda
3
star
42

submake

Use git to replay part of a bash pipeline.
Haskell
2
star
43

directed-graph-ui

A tool for creating directed graphs.
JavaScript
2
star
44

ice-cream-privacy

Haskell
2
star
45

rerec

Haskell
2
star
46

hs-promote

C++-style type promotion for Haskell's numeric hierarchy
Haskell
2
star
47

hint-demo

Haskell
2
star
48

trie-based-frp

An implementation of higher-order FRP based on shared tries instead of unsafePerformIO.
Haskell
2
star
49

glut-events

For writing GLUT's main loop in the style of Haskell's main function.
Haskell
2
star
50

reactive-banana-anti-tutorial

companion code for my blog post
Haskell
2
star
51

queues

Compare the performance of a few Haskell queue implementations.
Haskell
2
star
52

relocation-bug

Haskell
1
star
53

raml

C
1
star
54

contravariant-case

An API for Divisible and Decidable which looks like pattern-matching.
Haskell
1
star
55

ludum-dare-42

The theme for LD42 was "Running out of Space"
TypeScript
1
star
56

adicity

A DSL in which composition and application are unified.
Haskell
1
star
57

stack-bug

A demonstration of a bug which doesn't fit in a gist because it requires directories.
Haskell
1
star
58

free-premonoidal

Haskell
1
star
59

existentials

A type-level DSL for placing existential constraints on some arguments of a type constructor
Haskell
1
star
60

haskell-code-explorer-bug

a minimal repro
Haskell
1
star
61

croportunity-cost

A game about clicking and not clicking on plants.
Elm
1
star
62

ludum-dare-43

Haskell
1
star
63

timesheet

Simple text-based time tracking
Haskell
1
star
64

pure-framework-chat

Haskell
1
star
65

tic-tac-top

The AI for a tiny board game I invented.
Haskell
1
star
66

face-down

Haskell
1
star
67

install-before-test

How to configure project.cabal so that tests are run after the install.
Haskell
1
star
68

memento

Write a Virtual DOM for anything!
Haskell
1
star
69

dotfiles

My default setup, including config files and shell scripts.
Python
1
star
70

gif-browser

a tiny application for browsing through the frames of an animated gif.
Haskell
1
star
71

lens-syntax

Pointful syntax for optic compositions
Haskell
1
star