A minimal grep implementation in Rust. This is a learning project that recreates the core functionality of the Unix grep command. It searches for a text pattern in a file and prints out the matching lines. Simple, focused, and written in Rust.
- Case-sensitive search by default
- Case-insensitive search via environment variable
- Clean error handling
- Proper separation of concerns (library vs binary)
- Unit tests included
Build and run the project:
# Build the project
cargo build --release
# Search for a word in a file (case-sensitive)
cargo run -- <search_term> <filename>
# Example: search for "nobody" in the included poem
cargo run -- nobody poem.txtFor case-insensitive search, set the IGNORE_CASE environment variable:
# Case-insensitive search
IGNORE_CASE=1 cargo run -- nobody poem.txt# Find all lines containing "frog" in poem.txt
$ cargo run -- frog poem.txt
How public, like a frog
# Case-insensitive search for "NOBODY"
$ IGNORE_CASE=1 cargo run -- NOBODY poem.txt
I'm nobody! Who are you?
Are you nobody, too?cargo testThe test suite includes both case-sensitive and case-insensitive search tests.