Search string from files recursively
Project description
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.
Usage
findstring [OPTIONS] search_string
Options
search_string
: The string to search for in the files.
Optional Arguments
-
-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. -
-l
,--max_length
:
Maximum number of characters to be shown as a result. The default is 0, which means no limit is set. -
-t
,--text
:
Show the matched lines containing the search string in the output. -
-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 thepdfminer
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 thepython-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. This is done by decoding the binary content into ASCII. -
Context Display:
When the--text
option is enabled, the tool will display the lines containing the search string, with optional context provided by the--max_length
option.
Examples
Search for a string in the current directory
findstring "example_string"
Search for a string in a specific directory
findstring -d /path/to/directory "example_string"
Search in binary files and display matched files
findstring -b -t "example_string"
Search with verbose output
findstring -v "example_string"
Limit the length of the output context to 50 characters
findstring -l 50 "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.
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 findstring-0.2.tar.gz
.
File metadata
- Download URL: findstring-0.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4f6df5077efe0b8896f715ec3ba38356ebef20f6ea7dd8919932acd27a137ab |
|
MD5 | 29d27c1e7c4fce9073fc63efe3eb6285 |
|
BLAKE2b-256 | 3bfe319305cd616b544176a0e1eb8a0c4c422412eaa4a0c67f593d6d005bed64 |
File details
Details for the file findstring-0.2-py3-none-any.whl
.
File metadata
- Download URL: findstring-0.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d9712e813ba5168f78b5e8cebcd5067b2af62303e7010b4194bb0616f83b254 |
|
MD5 | b066813fa73438eaeb0e06117219463d |
|
BLAKE2b-256 | 50b0f2a309dd1b06d3f8a301d3e3f5e815897c9f9585b6c04cfe1f4a991ec6ef |