fzgrep: A zero-dependency, OpenMP-parallelized fuzzy line matcher in C
I built fzgrep , a lightweight, OpenMP-parallelized fuzzy line matcher written in pure C with zero external runtime dependencies. The Problem In standard UNIX pipelines, filtering text has two well-known extremes: grep / ripgrep : Incredibly fast for exact substrings and regex, but completely unforgiving when handling typos or fuzzy criteria. fzf : A masterpiece for interactive TUI navigation,…
Fzgrep is a C-based fuzzy line matcher that requires no external dependencies and can be used in pipelines. It strikes a balance between the speed of exact substring searches like grep and ripgrep, and the flexibility of fuzzy matching tools like fzf. The tool is designed to work with standard Unix pipelines, accepting input from stdin or files, and running in a headless environment.
Fzgrep uses a dynamic single-row Levenshtein distance algorithm, which requires less memory than storing a full $O(N \times M)$ distance matrix. It utilizes a chunk-based MapReduce model, where incoming lines are buffered into chunks (default 8,192 lines) and distributed across multiple CPU cores via OpenMP parallelization. This allows it to efficiently handle large text streams on multi-core systems.
The tool offers a word match mode (-w) that splits lines into space-delimited tokens, enabling the matcher to check individual words against a given pattern. When used with the -n flag, it provides compiler-friendly coordinate information for matched words, such as line number and column position.
Fzgrep can also report matches with similarity scores, which are displayed by default. This allows users to quickly identify the most relevant matches in a pipeline. For example, filtering a list of words for typo-tolerant matches can be done with the command: cat /usr/share/dict/words | fzgrep -j 8 -t 0.8 algotithm algorithm. The tool outputs matches with their respective similarity scores, such as 0.80 for "algorithm".
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
