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.
- Pattern Search: Search for a pattern (string or regex) within files.
- Case-Insensitive Search: Use the
-i
option for case-insensitive searching. - Line Numbers: Use the
-n
option to display line numbers alongside matching lines. - Regular Expression Support: Use the
-r
option to treat the pattern as a regular expression. - Recursive Search: Use the
-R
option to search files in subdirectories. - Highlight Matching Text: Use the
-c
option to highlight matching text in the output. - Help: Use the
-h
option to display help and usage information. - Pipe Support: Pass input through pipes from other commands, allowing you to use
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