A tiny grep -n clone written in Rust. It scans a file for a substring pattern and prints every matching line prefixed with its 1-based line number.
- Command-line interface powered by
clap - Shared search logic exposed through a
search_filefunction in the library crate - Case-insensitive (
-i/--ignore-case) and inverted (-v/--invert-match) filtering - Helpful error messages when files cannot be read
- Integration tests using
assert_cmd,predicates, andtempfile
- Rust toolchain (cargo + rustc). Install via rustup.
cargo run -- [OPTIONS] <pattern> <path>Options
-i,--ignore-case– match without case sensitivity-v,--invert-match– print only the lines that do not contain the pattern
Try it with this repository's README
cargo run -- --ignore-case readme README.mdInvert the match (prints non-matching lines):
cargo run -- --invert-match readme README.mdcargo testThis runs unit tests (when present) and the CLI integration test in tests/cli.rs.
Ideas for future improvements:
- Regex-based searches (e.g., using the
regexcrate) - Reading from
stdinand searching multiple files recursively - Additional flags such as
--context,--count, or recursive directory walking