smallgrep 0.1.1

A Lite version of a CLI tool grep made with rust
Documentation
  • Coverage
  • 83.33%
    10 out of 12 items documented4 out of 6 items with examples
  • Size
  • Source code size: 17.44 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.02 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 30s Average build duration of successful builds.
  • all releases: 29s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Deep-Thakkar-1910

smallgrep

smallgrep is a lightweight, beginner-friendly implementation of the classic Unix grep command, written in Rust 🦀.

This project is designed primarily as a learning crate, focusing on:

  • idiomatic Rust
  • clean CLI design
  • correctness over cleverness
  • understanding how real CLI tools are built and published

✨ Features

  • 🔍 Case-sensitive search (default)
  • 🔡 Case-insensitive search (-i, --insensitive)
  • 🎯 Exact (whole-word) matching (-e,--exact)
  • 🎨 Optional colorized output (-c,--colorize)
  • 📄 Simple, readable codebase
  • 📚 Well-documented with examples and tests

Installation

Install the binary using Cargo:

cargo install smallgrep

Usage

smallgrep <QUERY> <FILENAME> [OPTIONS]

Positional Arguments

  • QUERY
    The word or pattern to search for.

  • FILENAME
    The file to search in.

Options

  • -i, --insensitive
    Perform a case-insensitive search.

  • --exact
    Match the query as a whole word only.

  • --colorize
    Highlight matched text with color.

  • -h, --help
    Show help information.

  • -V, --version
    Show version information.


Examples

Basic case-sensitive search

smallgrep hello file.txt

Matches lines containing hello exactly as written.


Case-insensitive search

smallgrep hello file.txt -i

Matches:

hello
Hello
HELLO

Exact (whole-word) matching

smallgrep cat file.txt --exact

Matches:

cat
the cat sat
(cat)

Does NOT match:

concatenate
bobcat

Exact and case-insensitive matching

smallgrep cat file.txt --exact -i

Matches:

Cat
cAt
CAT

Only when cat appears as a whole word.


Colorized output

smallgrep error log.txt --colorize

Highlights matched words in color when output is printed to a terminal.

Note: Colors are automatically disabled when output is redirected to a file.


Combining multiple options

smallgrep rust README.md --exact -i --colorize

Documentation


License

Licensed under either of:

  • MIT License
  • Apache License, Version 2.0