Grep for Unstructured Multiline Paragraphs
Project description
grump
Grep for Unstructured Multiline Paragraphs
A multiline paragraph is a string in which there are no 'empty
lines' - two newlines separated only by whitespace. For example
given data.txt
:
This is
one multiline
paragraph.
This is
another
multiline
paragraph.
This one is too!
grump
takes a file and a list of strings and outputs all multiline
paragraphs of this file containing each string in the list. For
example:
$ grump -f data.txt this one
This is
one multiline
paragraph.
This one is too!
Installation
python3 -m pip install grump
Usage
usage: grump [-h] [-w] [-c] [-f FILENAME] regex [regex ...]
Grep for unstructured multiline paragraphs
positional arguments:
regex the string or regular expression to match against
optional arguments:
-h, --help show this help message and exit
-w, --word only match whole words
-c, --case-sensitive Perform case sensitive matching. By default, grump is case insensitive.
-f FILENAME, --file FILENAME
the file to grep (default: STDIN)
Examples
From the CLI
grump -f testdata.txt amy fred
grump amy fred < testdata.txt
cat testdata.txt | grump amy fred
grump --file testdata.txt amy fred --word --case-sensitive
grump -f testdata.txt amy fred -w -c
As a module
import grump
# with text from textfile.txt
with grump.Grump('textfile.txt', ('amy','fred')) as matches:
for p in matches:
print(p)
# with text from STDIN
with grump.Grump(None, ('amy','fred')) as matches:
for p in matches:
print(p)
# with non-default matching rules
with grump.Grump(
'textfile.txt',
('amy','fred'),
case_sensitive=True,
word=True
) as matches:
Contributing
- Fork the repository https://github.com/andrewsolomon/grump
- Make some changes
- Update
tests/test_grump.py
- Make sure tests pass
black grump/grump.py
black tests/test_grump.py
pytest
- Make a pull request
Releasing
Give it a new version:
bump2version --no-commit --no-tag patch
and remove --no-commit
and --no-tag
when you're sure. Then
git push
git push --tags
Note, "patch" indicates a bugfix or minor improvement.
- If there are new, backward compatible features change "patch" to "minor"
- If there are backward incompatible changes change "patch" to "major"
Package it:
python setup.py clean --all
rm -rf dist/ build/ grump.egg-info/ grump_andrewsolomon.egg-info/
python setup.py sdist bdist_wheel
Upload it to test pypi:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
install it from there:
python3 -m pip install --upgrade -i https://test.pypi.org/simple/ grump
Then upload it to pypi.org
twine upload dist/*
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
Built Distribution
File details
Details for the file grump-0.0.12.tar.gz
.
File metadata
- Download URL: grump-0.0.12.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
eaa636f582aefa39849961a8980127b9ba3b3424e2793ac87a7a206dd13b6574
|
|
MD5 |
bac5de5b3e9b542ee70af7a24e690d85
|
|
BLAKE2b-256 |
013ce198f0b42e3334a78493f2a7ec6a5d5dac43995074d913913297cd075984
|
File details
Details for the file grump-0.0.12-py3-none-any.whl
.
File metadata
- Download URL: grump-0.0.12-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
28ad02b23ce93f0e22cf884d23d124e418f52aaf598aea6ddc0558460d605f7f
|
|
MD5 |
e76394d8707f411107785d891b054be0
|
|
BLAKE2b-256 |
25a5049d7ecd027fc8bb8e93574198ba9e89da38d8ea754b000898905c019557
|