Name | findstring JSON |
Version |
0.6
JSON |
| download |
home_page | None |
Summary | Search string from files recursively including pdf and docx files |
upload_time | 2024-09-02 08:39:53 |
maintainer | None |
docs_url | None |
author | Katsutoshi Seki |
requires_python | >=3.10 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# findstring
This program, `findstring`, allows you to search for a specific string within files in a directory, including support for searching within PDF and DOCX files. It works similarly to the `grep -rI` command but adds the ability to read and search through PDF and DOCX files.
## Install
```bash
pip install findstring
```
## Usage
```bash
findstring [OPTIONS] search_string
```
## Options
- `search_string`: The string to search for in the files.
### Optional Arguments
- `-h`, `--help`:
Show the help message and exit. This option provides a summary of how to use `findstring`, including descriptions of all available options.
- `-b`, `--binary`:
Scan binary files as well. If this option is used, the tool will attempt to read binary files and search for the specified string.
- `-d`, `--directory`:
Root directory to start searching from. If not specified, the current directory (`.`) is used by default.
- `-t`, `--text`:
Show the matched lines containing the search string in the output.
- `-l`, `--max_length`:
Maximum number of characters to be shown as a result. The default is 0, which means no limit is set. When `--max_length` is specified, `--text` is also enabled.
- `-v`, `--verbose`:
Enable verbose output. The program will provide more detailed information about its operation, including which directories and files are being checked.
## Features
- **PDF Support**:
The program can search within PDF files using the `pdfminer` library. It extracts text from the PDF and searches for the specified string.
- **DOCX Support**:
DOCX files are also supported, with text extraction handled by the `docx` library.
- **Binary File Scanning**:
When the `--binary` flag is enabled, the program will attempt to read binary files and search for the specified string.
- **Context Display**:
When the `--text` option is enabled, the tool will display the lines containing the search string, with maximum numbers of characters specified by the `--max_length` option.
## Examples
### Search for a string in the current directory
```bash
findstring "example_string"
```
### Search for a string in a specific directory
```bash
findstring -d /path/to/directory "example_string"
```
### Search with verbose output and show matched lines
```bash
findstring -tv "example_string"
```
### Limit the length of the output text to 50 characters
```bash
findstring -l 50 "example_string"
```
### Search in binary files
```bash
findstring -b "example_string"
```
## Error Handling
The program will attempt to handle errors such as unreadable files gracefully. If an error occurs while reading a file, the program will skip the file and continue processing the rest, optionally displaying an error message if verbose mode is enabled.
## Highlighting Search Results
The program is configured to highlight matching search results in bold red text by default. This highlighting is controlled by the `GREP_COLORS` environment variable, specifically using the `mt=` option.
If you wish to change the color or style of the highlighted text, you can modify the `mt=` setting in the `GREP_COLORS` environment variable. The `mt=` value is a color code that specifies the style and color used for matching text.
For example:
- **Bold Red (default):** `mt=1;31`
- **Bold Green:** `mt=1;32`
- **Underline Blue:** `mt=4;34`
To apply a custom color, you can set the `GREP_COLORS` environment variable in your shell as follows:
```bash
export GREP_COLORS='mt=1;32'
```
This example would change the highlighted text to bold green.
The program automatically detects if the output is directed to a terminal (TTY). If not, it will print the plain text without any colorization.
## Using as a Library
You can use `findstring` as a library as:
```python
from findstring import findstring
findstring("/path/to/directory" "example_string")
```
Arguments of `findstring` function is as follows.
- **`root_dir`** (`str`):
The root directory to start searching from.
- **`search_string`** (`str`):
The string to search for within the files.
- **`verbose`** (`bool`, optional):
If `True`, print additional information during the search process. Default is `False`.
- **`show_text`** (`bool`, optional):
If `True`, display the matched line containing the search string. Default is `False`.
- **`max_length`** (`int`, optional):
Maximum number of characters to display in the result. Default is `0` (no limit).
- **`binary`** (`bool`, optional):
If `True`, scan binary files as well. Default is `False`.
Raw data
{
"_id": null,
"home_page": null,
"name": "findstring",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Katsutoshi Seki",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/13/67/1ea65b1dd2a625eb3dd41f0dc2dc337d68c4c5b68471fc7b4f6084bc1a76/findstring-0.6.tar.gz",
"platform": null,
"description": "# findstring\n\nThis program, `findstring`, allows you to search for a specific string within files in a directory, including support for searching within PDF and DOCX files. It works similarly to the `grep -rI` command but adds the ability to read and search through PDF and DOCX files.\n\n## Install\n\n```bash\npip install findstring\n```\n\n## Usage\n\n```bash\nfindstring [OPTIONS] search_string\n```\n\n## Options\n\n- `search_string`: The string to search for in the files.\n\n### Optional Arguments\n\n- `-h`, `--help`:\n Show the help message and exit. This option provides a summary of how to use `findstring`, including descriptions of all available options.\n\n- `-b`, `--binary`: \n Scan binary files as well. If this option is used, the tool will attempt to read binary files and search for the specified string.\n\n- `-d`, `--directory`: \n Root directory to start searching from. If not specified, the current directory (`.`) is used by default.\n\n- `-t`, `--text`: \n Show the matched lines containing the search string in the output.\n\n- `-l`, `--max_length`: \n Maximum number of characters to be shown as a result. The default is 0, which means no limit is set. When `--max_length` is specified, `--text` is also enabled.\n\n- `-v`, `--verbose`: \n Enable verbose output. The program will provide more detailed information about its operation, including which directories and files are being checked.\n\n## Features\n\n- **PDF Support**: \n The program can search within PDF files using the `pdfminer` library. It extracts text from the PDF and searches for the specified string.\n\n- **DOCX Support**: \n DOCX files are also supported, with text extraction handled by the `docx` library.\n\n- **Binary File Scanning**: \n When the `--binary` flag is enabled, the program will attempt to read binary files and search for the specified string.\n\n- **Context Display**: \n When the `--text` option is enabled, the tool will display the lines containing the search string, with maximum numbers of characters specified by the `--max_length` option.\n\n## Examples\n\n### Search for a string in the current directory\n\n```bash\nfindstring \"example_string\"\n```\n\n### Search for a string in a specific directory\n\n```bash\nfindstring -d /path/to/directory \"example_string\"\n```\n\n### Search with verbose output and show matched lines\n\n```bash\nfindstring -tv \"example_string\"\n```\n\n### Limit the length of the output text to 50 characters\n\n```bash\nfindstring -l 50 \"example_string\"\n```\n\n### Search in binary files\n\n```bash\nfindstring -b \"example_string\"\n```\n\n## Error Handling\n\nThe program will attempt to handle errors such as unreadable files gracefully. If an error occurs while reading a file, the program will skip the file and continue processing the rest, optionally displaying an error message if verbose mode is enabled.\n\n## Highlighting Search Results\n\nThe program is configured to highlight matching search results in bold red text by default. This highlighting is controlled by the `GREP_COLORS` environment variable, specifically using the `mt=` option.\n\nIf you wish to change the color or style of the highlighted text, you can modify the `mt=` setting in the `GREP_COLORS` environment variable. The `mt=` value is a color code that specifies the style and color used for matching text.\n\nFor example:\n- **Bold Red (default):** `mt=1;31`\n- **Bold Green:** `mt=1;32`\n- **Underline Blue:** `mt=4;34`\n\nTo apply a custom color, you can set the `GREP_COLORS` environment variable in your shell as follows:\n\n```bash\nexport GREP_COLORS='mt=1;32'\n```\n\nThis example would change the highlighted text to bold green.\n\nThe program automatically detects if the output is directed to a terminal (TTY). If not, it will print the plain text without any colorization.\n\n## Using as a Library\nYou can use `findstring` as a library as:\n\n```python\nfrom findstring import findstring\nfindstring(\"/path/to/directory\" \"example_string\")\n```\n\nArguments of `findstring` function is as follows.\n\n- **`root_dir`** (`str`): \n The root directory to start searching from.\n\n- **`search_string`** (`str`): \n The string to search for within the files.\n\n- **`verbose`** (`bool`, optional): \n If `True`, print additional information during the search process. Default is `False`.\n\n- **`show_text`** (`bool`, optional): \n If `True`, display the matched line containing the search string. Default is `False`.\n\n- **`max_length`** (`int`, optional): \n Maximum number of characters to display in the result. Default is `0` (no limit).\n\n- **`binary`** (`bool`, optional): \n If `True`, scan binary files as well. Default is `False`.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Search string from files recursively including pdf and docx files",
"version": "0.6",
"project_urls": {
"Homepage": "https://pypi.org/project/findstring/",
"Source": "https://github.com/sekika/findstring"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3761bc5db13537743a6e7134be561b4e0aa3532ae7d40294ae992932cc0b1493",
"md5": "9c2ec5f30851b4f4985601f0c0208353",
"sha256": "60778ea23ffb4d95b92dd0019e90bac15dba58073fbba3fcd8ccacc932f46d92"
},
"downloads": -1,
"filename": "findstring-0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9c2ec5f30851b4f4985601f0c0208353",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 9404,
"upload_time": "2024-09-02T08:39:52",
"upload_time_iso_8601": "2024-09-02T08:39:52.286038Z",
"url": "https://files.pythonhosted.org/packages/37/61/bc5db13537743a6e7134be561b4e0aa3532ae7d40294ae992932cc0b1493/findstring-0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "13671ea65b1dd2a625eb3dd41f0dc2dc337d68c4c5b68471fc7b4f6084bc1a76",
"md5": "4cae4d287798e7b37f625c369126b7fd",
"sha256": "41c46792275e141da6e605d9d380a9ba455a813b789f6510fbc759a086510d9a"
},
"downloads": -1,
"filename": "findstring-0.6.tar.gz",
"has_sig": false,
"md5_digest": "4cae4d287798e7b37f625c369126b7fd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 9391,
"upload_time": "2024-09-02T08:39:53",
"upload_time_iso_8601": "2024-09-02T08:39:53.692011Z",
"url": "https://files.pythonhosted.org/packages/13/67/1ea65b1dd2a625eb3dd41f0dc2dc337d68c4c5b68471fc7b4f6084bc1a76/findstring-0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-02 08:39:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sekika",
"github_project": "findstring",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "findstring"
}