This is my minigrep tool made only for learning rust, trying to learn from the famous ripgrep. It is aimed to provided similar functionality with grep. But for now it is still work in progress. There are currently two crate here. First is argtool, for parse sys arg, used by minigrep. The other is grep, the main program for minigrep.
# cd to this repo
cargo build --release
# This is binary location
./target/release/minigrep -h
Basic pattern
./minigrep "YourPattern" "YourDir/*"
Print all fn in codes.
./target/release/minigrep "fn" "minigrep/*"
Print help
./target/release/minigrep -h
./target/release/minigrep --help
Print with line number and the following two line.
./target/release/minigrep "fn" "minigrep/*" -n -B 2
Multiple match: struct, trait, and enum
./target/release/minigrep "trait" "minigrep/*" -n -M "struct" -M "enum" -B 3 -A 1
Extract match pattern, here the pattern is function name
🪲: There are some wrong behavior in extract, need capture group. If parenthesis is added, that is "fn [A-Za-z0-9_]+\("
Some of matched line will be empty.
./target/release/minigrep "fn" "minigrep/*" -n -E "fn [A-Za-z0-9_]+"
Replace ->
with ==>
🪲: if replacer is -->
there will be error. -
need to be escaped. We need "\->"
for -R
only, there is no need to specify it twice.
./target/release/minigrep "\->" "minigrep/*" -n -R "\->" -r "==>"
Done by hyperfine! It is still slow compared to ripgrep, at least close to grep. Keep working!
My argparser. Go to github page generated by rust docs