| Crates.io | greplite |
| lib.rs | greplite |
| version | 0.2.0 |
| created_at | 2024-12-24 12:47:58.378134+00 |
| updated_at | 2024-12-24 12:47:58.378134+00 |
| description | A simple implementation of the `grep` command. |
| homepage | |
| repository | https://github.com/JonWatkins/greplite |
| max_upload_size | |
| id | 1493853 |
| size | 35,425 |
greplite is a simplified version of the grep command written in Rust. It allows you to search for a pattern within
files, with support for case-insensitive searching and line numbers. This is my modified version of the minigrep
implementation in the Rust Book.
-i option for case-insensitive searching.-n option to display line numbers alongside matching lines.-r option to treat the pattern as a regular expression.-R option to search files in subdirectories.-c option to highlight matching text in the output.-h option to display help and usage information.greplite in conjunction with other
Unix-like tools.Search for the pattern "rust" in a file:
greplite "rust" file.txt
Perform a case-insensitive search using the -i option:
greplite -i "rust" file.txt
Show line numbers of the matching lines using the -n option:
greplite -n "error" log.txt
Search in multiple files:
greplite "hello" file1.txt file2.txt
greplite supports regular expressions with the -r option. For example, to search for lines starting with "Rust"
(case-sensitive), you can use:
greplite -r "^Rust" file.txt
To make the regex search case-insensitive, use both -r and -i:
greplite -r -i "^rust" file.txt
Use the -R option to search recursively through all files in the specified directory and its subdirectories.
greplite -R "pattern" ./my_directory
greplite can also be used in combination with commands like cat, echo, or even complex command pipelines. For
instance, if you want to search for a specific string in a file after filtering the contents with grep, you can
chain the commands like this:
cat file.txt | greplite "pattern"
Using greplite in a Pipeline with Other Filters:
cat large_log.txt | greplite -i "error" | sort | uniq
To see the available options and usage instructions, run the command with the -h option:
greplite -h