A simple grep-like command-line tool written in Rust that searches for text patterns in files.
Make sure you have Rust installed on your system.
# Clone the repository
git clone git@github.com:yourusername/minigrep.git
cd minigrep
# Build the project
cargo build --release
# The binary will be in target/release/minigrep# Basic search (case-sensitive)
cargo run -- --query "pattern" --file-path poem.txt
# Short form
cargo run -- -q "pattern" -f poem.txt
# Case-insensitive search
cargo run -- --query "pattern" --file-path poem.txt --ignore-case
cargo run -- -q "pattern" -f poem.txt -i
# Show line numbers
cargo run -- --query "pattern" --file-path poem.txt --line-number
cargo run -- -q "pattern" -f poem.txt -n
# Get help
cargo run -- --help-q, --query <QUERY>- The pattern to search for (required)-f, --file-path <FILE_PATH>- The file to search in (required)-i, --ignore-case- Ignore case when searching (optional, default: false)-n, --line-number- Print line numbers with output (optional, default: false)
Given a file poem.txt:
Rust:
safe, fast, productive.
Pick three.
Trust me.
$ cargo run -- -q "rust" -f poem.txt
# No results (no lowercase "rust")
$ cargo run -- -q "Rust" -f poem.txt
Rust:$ cargo run -- -q "rust" -f poem.txt -i
Rust:
Trust me.$ cargo run -- -q "rust" -f poem.txt -i -n
1:Rust:
4:Trust me.cargo testminigrep/
├── src/
│ ├── main.rs # Entry point and CLI handling
│ └── lib.rs # Search logic and functions
├── Cargo.toml # Project dependencies
├── Cargo.lock # Dependency lock file
└── README.md # This file
- clap v4.5.48 - Command line argument parser
This project is inspired by the Rust Programming Language Book, Chapter 12.