Skip to main content

cgrep

A command line utility to grep for blocks of text

This tool displays a block of text that matches a regex.

Usage

usage: cgrep [-h] [-k PATTERN] [-i] [-v] [--color] PATTERN [FILE [FILE ...]]

grep blocks of text.

positional arguments:
  PATTERN               pattern to grep for
  FILE                  file(s) to grep.

optional arguments:
  -h, --help            show this help message and exit
  -k PATTERN, --block-marker PATTERN
                        regex pattern describing the start of a block
                        (default=^$)
  -i, --ignore-case     ignore case distinctions
  -v, --invert-match    select non-matching blocks
  --color               use markers to highlight the matching strings

Example

Given the following file,

2018-10-05
Nothing interesting happened.

2018-10-06
cgrep released on github.

2018-10-07
Nobody knows what the future will bring.

Running cgrep on the file produces the following output:

$ cgrep 2018-10-06 diary.txt

2018-10-06
cgrep released on github.

By default, a block begins and ends with an empty line. This default can be changed with the -k option.

Footnotes

cgrep was inspired by mgrep. mgrep was (is?) a UNIX command line tool to grep emails on UNIX accounts, stored as flat files in a format called "mbox". mgrep-ing a pattern in an mbox displayed the entire email containing the pattern. cgrep is a generalized version of the mgrep that can grep for any block of text and not just emails in an mbox. Passing -k '^From ' option to cgrep is practically equivalent to mgrep.

The "c" in cgrep is largely historical. It originally stood for "context".

Metadata

Release files for cgrep 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cgrep 1.0.0
File Size Uploaded Provenance
cgrep-1.0.0.tar.gz 8.2 kB Without provenance Details

Release files / cgrep-1.0.0.tar.gz

Download URL cgrep-1.0.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
87930c343adb1c1d6d0a531e528f26cadf9adc075e4a6e5b29add634b7471b47
BLAKE2b-256 checksum
How to use checksums
6f7f968d19c91b5baa39bbf701b3764542529bb683047bfadb50a8a1634ad1cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.9

Security for cgrep 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page