Skip to main content

A command line utility to grep for blocks of text

Project description

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".

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cgrep-1.0.0.tar.gz (8.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page