This is a home page for cgrep, a grep-like tool with enhanced performance and may additional features, including the ability to output the context of the matching lines.
Download: source tarball
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
Just as in the standard grep, you can find a single line with cgrep:
unix_prompt> cgrep forbid COPYING To protect your rights, we need to make restrictions that forbid unix_prompt>You can also print the whole matching paragraph by specifying a number of lines. Here, we print the blank line before the match and the trailing four lines, the last of which is also blank.
unix_prompt> cgrep -1 +4 forbid COPYING ======================================== To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.Since this is a text document, there are patterns in the text, that is, it is broken up into paragraph separated by blank lines. Thus, you can also print a matching paragraph by specifying "^$" as a window delimiter, where '^' matches the beginning of a line, '$' matches the end, so the pattern matches lines that are blank (contain nothing).
unix_prompt> cgrep +-w "^$" forbid COPYING ======================================== To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.The -I options, used in conjunction with -w allow you to not print the window delimiting lines:
unix_prompt> cgrep -+I2 +-w "^$" forbid COPYING ======================================== To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
The following example will print all paragraphs in an nroff source file that contain (among others) the strings "Connecticut", "Conneticut", "Coneticut", and "Conecticut". It will not match "Connecticot" or "Connectickut", because "cut" must be matched exactly. It will also not match "Conetacut", because three errors is one error too many.
cgrep -+w '^\.P$' -A2 '<Con>necti<cut>' file
NOTE: The -A option flag must appear AFTER the delimiter '^\.P$' or else the approximate matching would apply to the paragraph delimiter as well.
The following example will print each line that contains (among others) the strings "Connecticut", "Connectickut", and "Connectacut". It will not match "Conneticut", because the cost of a deletion error, four, is too high. It will also not match "Connectakut", because the total cost of two substitution errors, four, is too high. It will also not match "Colnnecticut", because "Con" must be matched exactly, even though the cost of an insertion is zero.
cgrep -A3 +C0 -C4 +-C2 '<Con>necticut' file
Either of the following examples will print each line that contains no more than three non-numeric characters, and any number of numeric characters.
cgrep -A3 '^[0-9]*$' file
or
cgrep -x -A3 '[0-9]*' file