Skip to content
Calebp98Public

About

Quick implementation of grep in rust

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minigrep

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.

Features

  • Case-sensitive search by default
  • Case-insensitive search via environment variable
  • Clean error handling
  • Proper separation of concerns (library vs binary)
  • Unit tests included

Usage

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.txt

For case-insensitive search, set the IGNORE_CASE environment variable:

# Case-insensitive search
IGNORE_CASE=1 cargo run -- nobody poem.txt

Examples

# 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?

Running Tests

cargo test

The test suite includes both case-sensitive and case-insensitive search tests.

About

Quick implementation of grep in rust

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages