xgrep
Documentation
Can be found at https://xgrep.readthedocs.io
Installation
$ pip install xgrep
Usage is similar to regular grep. Give a pattern and then one or more
filenames. There are various options (some with the same name and effect as
grep options, like -c, -h, -H, -i, -q, and -v). Run xgrep --help for a full listing.
Example usage
To give an example of using xgrep, suppose you have an Excel file (example.xlsx)) with a
sheet that looks like this:
You can download
example.xlsx
(or find it in the docs/source/excel directory in the repo) if you want to try
the following commands.
Find cells based on a regular expression
Look for the regular expression 'Xia|radius|Jilin':
$ xgrep 'Xia|radius|Jilin' example.xlsx
Note that the command-line output is all text. It is produced using the Table class of the wonderful rich package.
Display the row and column information
Add the row numbers (--rn) and Excel column (--ec) information from the
input Excel:
$ xgrep --rn --ec 'Xia|radius|Jilin' example.xlsx
De-emphasize unmatched cells
If you don't care about the values in cells that were not matched, you can
give a value to show in unmatched (-u) cells:
$ xgrep -u . --rn --ec 'Xia|radius|Jilin' example.xlsx
Only show matching columns
To exclude columns with no matching cells, you can show only matching columns
(--omc):
$ xgrep --omc --rn --ec 'Xia|radius|Jilin' example.xlsx
Write CSV (or TSV)
The default output format is a
rich
Table. You can also
produce CSV, TSV, or Excel using the --format option:
$ xgrep --format csv 'Xia|radius|Jilin' example.xlsx
If you use --format excel you will also need to give an output filename
using --out.
Usage
Usage: xgrep [OPTIONS] PATTERN FILENAMES...
Command-line interface.
Options:
-o, --out FILE The output file. If not given, output is
written to standard out. Note that if the
--quiet (-q) option is also given, no output
will be written to the output file.
--header / --no-header Don't look for a header line in input files.
In this case, text in what would otherwise
be considered a header can also be matched
by the grep pattern.
--skip INTEGER RANGE Skip this many rows at the start of the
input file(s). [x>=0]
--format [csv|excel|rich|tsv] The output format. The 'rich' format
produces a rich Table (see https://rich.read
thedocs.io/en/stable/tables.html).
-c, --count Only print the number of matching lines
(like grep -c).
--width INTEGER The width to use for --format rich tables.
-v, --invert Only output rows that do not match (like
grep -v).
-q, --quiet, --silent Do not show any output, just exit with a
status indicating whether a match was found
(0) or not (1) (like grep -q).
--ignore-missing-sheets, --ims Do not exit if a requested sheet cannot be
found in an input Excel file. A warning will
be printed unless --quiet is used.
--only-matching-cols, --omc, --mco
Only show columns that have a matching cell.
-i, --ignore-case Ignore case while matching (like grep -i).
--color TEXT The highlight color.
-u, --unmatched TEXT The string to show for cells whose values do
not match. If not given, non-matching cells
are shown with their value (in which case
you will need to use the output color to see
matches).
-n, --row-numbers, --rn, --line-number
Show row numbers (like grep -n).
--col-numbers, --cn Show numeric column numbers. For alphabetic
Excel column labels, use --excel-cols.
--excel-cols, --ec Add Excel column labels to column names.
-b, --basename Only show basenames of input files in the
output (and in Excel sheet names, in the
case of --format excel).
--save-empty-output, --seo If there are no matches in a file (or Excel
sheet), nothing will be written to the
output file (so the output file will not
exist after xgrep exits). Use this option to
force the writing of empty output files (and
creation of empty Excel worksheets in the
case of --format excel).
Filenames: [mutually_exclusive]
Whether to display names of matching files.
-H, --filenames-always, --fa Always print the name of matching files
(like grep -H).
-h, --no-filename, --nf Never print the name of matching files (like
grep -h).
--only-filename, --of Only print the names of matching files, not
their matched content.
--sheet-name, --sn TEXT The name(s) of the sheet(s) to read. May be
repeated. Cannot be used with --sheet-id.
--sheet-id, --si INTEGER The numeric number(s) of the sheet(s) to
read. The default is to search all workbook
sheets in all Excel files (this is
equivalent to --sheet-id 0). Individual
sheet numbering starts from 1. May be
repeated. Cannot be used with --sheet-name.
--sheet-separator, --ss TEXT The string used to separate filenames from
sheet names when --format excel is used and
multiple files are being searched. Note that
Excel does not allow some characters (e.g.,
':') in sheet names.
--version Show the version and exit.
--help Show this message and exit.
Todo
- Document
format,polars_df, andrich_table(inreadthedocs.io). - Can
clickallow a-eoption that also can be used to specify the pattern? - Write tests for unequal numbers of cols.
Metadata
Release files for xgrep 0.2.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xgrep-0.2.12.tar.gz | 4.8 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xgrep-0.2.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.8 MB
Release files / xgrep-0.2.12.tar.gz
| Download URL | xgrep-0.2.12.tar.gz |
|---|---|
| Size | 4.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b880d6b614431d5d74d642bf67e84db4e2a278ce53b9891f16695c9eefaa9ad1
|
|
BLAKE2b-256 checksum How to use checksums |
454d460275cf9fed0337798761b033ea7826831ef029de105f7e36e9232d4421
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.6
|
Release files / xgrep-0.2.12-py3-none-any.whl
| Download URL | xgrep-0.2.12-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4586dd0f52352d11abb12140de3a5d38b4853562cc97d0bdbd60f461feb2529
|
|
BLAKE2b-256 checksum How to use checksums |
5fbb1767105f6f49d0a53df18546c3f8f4a1d8d7beba9391a9d7bfd56773ef47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.6
|
Security for xgrep 0.2.12
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.