A simple command-line text search utility written in Rust. Search for patterns in files with support for case-sensitive and case-insensitive matching.
- Case-sensitive search: Find exact matches of your query
- Case-insensitive search: Find matches regardless of letter casing
- Simple CLI: Easy-to-use command-line interface
- File reading: Efficiently reads and searches through file contents
Make sure you have Rust installed, then:
cargo build --releaseThe compiled binary will be available at target/release/minigrep.
cargo run -- <query> <file>Example:
cargo run -- "safe" poem.txtSet the IGNORE_CASE environment variable to perform case-insensitive search:
IGNORE_CASE=1 cargo run -- <query> <file>Example:
IGNORE_CASE=1 cargo run -- "rust" poem.txtsrc/
├── main.rs - Entry point, CLI argument parsing, and file I/O
└── lib.rs - Core search functions and tests
Run the test suite:
cargo testThe project includes tests for:
- Case-sensitive search functionality
- Case-insensitive search functionality
- Correct filtering of matching lines
Given a file poem.txt with content:
Rust:
safe, fast, productive.
Pick three.
Running:
cargo run -- "safe" poem.txtWill output:
safe, fast, productive.
MIT