#grep #file-search #string-search #command-line #mini-grep #command-line-interface #applications

bin+lib rahat3062_minigrep

A light-weight & minimal implementation of the grep cli app

4 releases

0.1.3 Apr 30, 2024
0.1.2 Apr 30, 2024
0.1.1 Apr 30, 2024
0.1.0 Apr 30, 2024

#1317 in Text processing

MIT/Apache

8KB
107 lines

rahat3062_minigrep

rahat3062_minigrep is a light-weight and minimal implementation of the grep command-line application. It is written in Rust and can be used both as a standalone application and as a library for other Rust programs.

Binary Crate

install via:

cargo install rahat3062_minigrep && \
alias minigrep = rahat3062_minigrep

The binary crate provides a command-line interface to the grep functionality. You can use it to search for a string in a file. Here's how to run it:

minigrep <query> <filename> -s

Replace with the string you want to search for and with the path to the file you want to search in and use -s for sensitive search.

If needed you can also take input from the stdin via pipelining:

history | minigrep cargo

Library Crate

The library crate provides a run function that you can use to perform a grep search programmatically. Here's an example:

use rahat3062_minigrep::{Config, run};

let config = Config {
    query: "my query".to_string(),
    filename: Some("my_file.txt".to_string()),
    sensitive: false,
};

let result = run(config);

In this example, run searches for "my query" in "my_file.txt" and returns the matching lines. The search is case-insensitive because sensitive is false.

Dependencies

~1–12MB
~76K SLoC