haystack-tools

Small C tools for finding things in very large files by byte offset.

Search by regex, then read the bytes around each match.

FinishedCLIC, Hyperscan, MesonGPL-3.0-or-later

Why

Small C tools for one job: finding things in very large files by byte offset, and reading the bytes around them. I wrote them in 2021, said it was too early to ask how to use them, and two years later published them anyway, flaws included.

Better and safer equivalents exist: ugrep for search, less with P for paging, xxd for hex.

The tools

ToolDoes
searchRegex search with Hyperscan, consuming the file in chunks, printing match offsets
pickReads offset left right from stdin, prints the raw bytes around the offset
hexSame as pick, output as hex

A planned page never happened.

Usage

$ meson setup build && cd build && meson compile
$ ./search "test:" build.ninja 2>/dev/null
MATCH: 1960
MATCH: 2016
$ echo "1960 11 22" | ./pick build.ninja
offset: 1949, margin: 33
data:
build test: phony meson-internal_

search finds the offsets; pick and hex look at what is there.