grep 0.9.0
dotnet tool install --global grep --version 0.9.0
dotnet new tool-manifest
dotnet tool install --local grep --version 0.9.0
#tool dotnet:?package=grep&version=0.9.0
nuke :add-package grep --version 0.9.0
grep/c# v0.9.0.0
Inspired by GNU grep
Syntax:
grep [OPTIONS] PATTERN [FILE [FILE ..]]
Examples
grep -nm 3 class *.cs --color black,yellow -X obj,bin
dir2 -sb *.cs --within 4hours | grep -n class -T -
- Options can be stored in envir var
grep. Link - Link to tool
dir2
Common Options
| Shortcut | for Option | with | Required | Can be stored in Envir grep? |
|---|---|---|---|---|
-c |
--count-only |
on |
No | |
-l |
--file-match |
on |
No | |
-r |
--sub-dir |
on |
No | |
-v |
--invert-match |
on |
No | |
--color |
COLOR | Yes, Link | ||
--map-shortcut |
a=b[,x=y] | Stored only in the envir Link | ||
-i |
--case-sensitive |
off |
Yes | |
-m |
--max-count |
NUMBER | Yes | |
-n |
--line-number |
on |
Yes | |
-w |
--word |
on |
Yes | |
-x |
--excl-file |
FILE | Yes, Link | |
-X |
--excl-dir |
DIR | Yes, Link |
Demo

Major Bug Fix to v0.0.2
- "Word search" now properly shows "the beginning of a line" and "the end of a line".
Major Imporvement to v0.0.2
Command line parameter
FILEnow can be a wild-card (e.g.*.cs) and including a path (e.g.zip2\*.cs).A color option
--coloris added for highlight background and group highlight.An option
--search(-e) is added for multiple patterns.An option
--sub-dir(-r) is added for recursivly reading files under directories.An option
--fixed-strings(-F) is added. That is,c++ -Fis same toc\+\+An option
--max-count(-m) is added for max finding count. The reporting finding count could be more than the number if the last find matched line contains several findings.Some options can be stored in environment variable
grep. For example,
| OS/Shell | Environement Setting |
|---|---|
| Win | set grep= -ni; --color red,yellow,9,black,gray; |
| bash | export grep=" -ni; --color red,yellow,9,black,gray;" |
** Any leading spaces will be ignored.
** Semi-comma is an optional separator just for friendly reading.
Important Differences to GNU grep in Linux and macos
GNU option
--include=GLOBis NOT provided. And wild-card parameters can be leading by a comma, e.g.,*.csand,*.cs,*.py.The above feature of comma-combining can be turn-off by option
--split-file-by-comma off.grep/c#ignores command line parameter--color=autoby a default option--skip-arg auto.
Major Differences to GNU grep
Excluding filenames can be combined by comma. e.g.
-x test*.cs,demo*.cs.Excluding directories can be combined by comma. e.g.
-X bin,obj,packag*.The above feature of comma-combining can be turn-off by option
--split-file-by-comma off.Directory separator can be included in excluding directory. e.g.
-X obj\re*e.Pause option
--pauseis added with default valueon.An option
--totalis added for grand total sum reporting.--total onlyprints the grand total sum line only.An option
--trimis added for removal of spaces at the beginning and at the end of a matched line.An option
--map-shortcutcan be defined by environement variablegrepto change shortcut setting. For example:
| OS/Shell | Environement Setting |
|---|---|
| Win | set grep=--map-shortcut s=r,Q=q; -X obj,bin; |
| bash | export grep="--map-shortcut s=r,Q=q; -X obj,bin;" |
Then the following command will read each *.cs file on each sub-directory excluing obj and bin.
grep -s using ,*.cs
Known Issuses
Under Windows Terminal, the program CANNOT display black background color to the following color scheme.
* One Half Light
* Solarized Light
* Tango Light
Yung, Chun Kau
2024 April
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
grep