awk-rs
A 100% POSIX-compatible AWK implementation in Rust with GNU AWK (gawk) extension support.
Overview
awk-rs aims to be a drop-in replacement for AWK that faithfully implements the POSIX AWK specification while also supporting common GNU AWK extensions. Written in Rust for reliability and performance.
Goals
- Complete POSIX AWK compatibility
- GNU AWK (gawk) extension support
- Identical output behavior to existing AWK implementations
- Clear, informative error messages
- Modern Rust codebase with minimal dependencies
Installation
From Source
The binary will be at target/release/awk-rs.
From crates.io
Usage
# Run an AWK program directly
# Process files
# Set field separator
# Set variables before execution
# Run program from file
Command-Line Options
| Option | Description |
|---|---|
-F fs |
Set field separator (can be a regex) |
-v var=val |
Assign variable before program execution |
-f progfile |
Read AWK program from file |
--posix |
Strict POSIX mode (disable extensions) |
--version |
Print version information |
--help |
Print usage help |
Examples
Print specific columns
|
# Output: two
Sum numbers in a file
Filter lines with pattern
Field separator and formatting
Associative arrays
Compatibility
awk-rs aims for 100% compatibility with:
- POSIX AWK - The baseline specification
- gawk - GNU AWK extensions
- mawk - Performance-oriented AWK
- nawk - One True AWK
Supported Features
- All POSIX AWK operators and statements
- User-defined functions
- Associative arrays
- Regular expression patterns
- Field splitting and manipulation
- Printf formatting
- I/O redirection and pipes
- Built-in string and math functions
- GNU AWK extensions (optional)
Building & Development
Requirements
- Rust 1.85+ (2024 edition)
- Cargo
Build
Project Structure
src/
├── main.rs # CLI entry point
├── lib.rs # Public API
├── error.rs # Error types
├── lexer/ # Tokenization
├── parser/ # Parsing & AST
├── interpreter/ # Execution engine
├── runtime/ # Variables, arrays, fields
└── io/ # Input/output handling
License
Licensed under either of:
at your option.
Copyright © 2026 Pegasus Heavy Industries LLC
Testing
awk-rs has comprehensive test coverage:
Test Coverage
- Unit tests: 170 (lexer, parser, interpreter, value system)
- E2E tests: 412 (complete AWK programs)
- CLI tests: 19 (command-line interface)
- Compatibility tests: 34 (gawk comparison)
- Doc tests: 4 (API examples)
- Coverage: 86% (library code)
Benchmarking
Contributing
Contributions welcome! Please read CONTRIBUTING.md for guidelines.
Quick checklist:
- Ensure POSIX AWK compatibility
- Add tests for new functionality
- Run
cargo fmtandcargo clippy - Check TODO.md for the roadmap
Security
See SECURITY.md for security policy and reporting vulnerabilities.
Acknowledgments
- The original AWK authors: Aho, Weinberger, and Kernighan
- The GNU AWK project for comprehensive documentation
- The Rust community