A 100% POSIX-compatible AWK implementation in Rust with GNU AWK (gawk) extension support.
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.
- 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
git clone https://github.com/pegasusheavy/awk-rs.git
cd awk-rs
cargo build --releaseThe binary will be at target/release/awk-rs.
cargo install awk-rs# Run an AWK program directly
awk-rs 'BEGIN { print "Hello, World!" }'
# Process files
awk-rs '{ print $1 }' file.txt
# Set field separator
awk-rs -F: '{ print $1 }' /etc/passwd
# Set variables before execution
awk-rs -v name="Alice" 'BEGIN { print "Hello, " name }'
# Run program from file
awk-rs -f program.awk input.txt| 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 |
echo "one two three" | awk-rs '{ print $2 }'
# Output: twoawk-rs '{ sum += $1 } END { print sum }' numbers.txtawk-rs '/error/ { print }' logfile.txtawk-rs -F: '{ printf "User: %-20s Shell: %s\n", $1, $7 }' /etc/passwdawk-rs '{ count[$1]++ } END { for (word in count) print word, count[word] }' words.txtawk-rs aims for 100% compatibility with:
- POSIX AWK - The baseline specification
- gawk - GNU AWK extensions
- mawk - Performance-oriented AWK
- nawk - One True AWK
- 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)
- Rust 1.85+ (2024 edition)
- Cargo
cargo build # Debug build
cargo build --release # Release build
cargo test # Run testssrc/
├── 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
Licensed under either of:
at your option.
Copyright © 2026 Pegasus Heavy Industries LLC
awk-rs has comprehensive test coverage:
cargo test # Run all 639 tests
cargo test --test e2e # E2E tests (412 tests)
cargo test --test gawk_compat # gawk compatibility tests (34 tests)- 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)
cargo bench # Run Criterion benchmarksContributions 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
See SECURITY.md for security policy and reporting vulnerabilities.
- The original AWK authors: Aho, Weinberger, and Kernighan
- The GNU AWK project for comprehensive documentation
- The Rust community