5 releases
0.1.4 | Jun 23, 2020 |
---|---|
0.1.3 | May 21, 2020 |
0.1.2 | May 18, 2020 |
0.1.1 | May 16, 2020 |
0.1.0 | May 15, 2020 |
#1854 in Text processing
17KB
246 lines
grep-rs
A grep-like library written in rust
Currently working features
Searching through files
Searching through standard input
Excluding patterns
Printing all lines before the first instance of the pattern
Printing all lines after the first instance of the pattern
Case Insensitivity
(NEW) Regex
Examples
Examples take place in hypothetical directory containing
Basic_file_1.txt Basic_file_2.txt
Basic_file_3.txt Basic_file_4.txt
see examples/
or run cargo run --example [file_name]
lib.rs
:
grep-rs is a simple tool for searching through text
Currently Working Features
- Support for searching through files
- Support for searching through standard input
- Searching through text that includes specific patterns
- Searching through text that excludes specific patterns
- Printing all lines before the first instance of the pattern
- Printing all lines after the first instance of the pattern
- Case Insensitivity
- Simple Regular Expressions
Installation
Add this to your Cargo.toml
libgrep-rs = "0.1.3"
Example
use libgrep_rs::searcher::Searcher;
use libgrep_rs::options::Options;
fn main() {
let options = Options::default();
let text = String::from("Hello World\n libgrep-rs test");
let pattern = String::from("World");
let searcher = Searcher::new(pattern, text, options, Some(String::from("\n")));
//Some(String::from("\n")) is the deliminator, it could be anything
//If set to None, it will use the default "\n"
let output = searcher.search();
println!("{}", output);
}
If it worked, the output will be
Hello World
You can see other examples in the examples/ directory
Dependencies
~2.1–3MB
~54K SLoC