findany
A command-line utility that retains only those lines from a text file or standard input that contain at least one substring from a list.
Features
- Search for multiple substrings. It is designed for efficient matching of millions of substrings.
- Reads from standard input or a text file.
- Writes filtered lines to standard output or redirects them to a text file.
- Optional case-insensitive search.
- Optional inversion of search.
- Optionally prints only the first matched substring instead of the entire line (incompatible with inverted search).
- Supports binary files.
- Progress bar to show search progress when processing large files, if the output is redirected to a file.
- Runs on Windows and Linux.
Installation
Option 1: Use npm
npm i -g findany
Option 2: Use pip
pip install findany
On Windows, make sure the /Scripts directory is added to PATH.
Option 3: Download binary
- Download the latest release from the Releases page.
- Save it to any folder (e.g.
/usr/local/bin/orC:\Users\<user>\AppData\Local\), add that folder to thePATHvariable. - Make executable if needed (
chmod +x /usr/local/bin/findany).
Build
The program is written in C and can be compiled with gcc.
It is recommended to enable SSE4.1 for low-level optimizations.
gcc -msse4.1 ./src/findany.c -o findany -O3
Test
Functional tests are configured using YAML files and run with pytest.
cd ./test && python -m pytest ./test.py
Usage
findany [OPTIONS] [SUBSTRINGS] [FILE]
Options
-i, --case-insensitive: Perform a case-insensitive search. By default, searches are case-sensitive.-v, --invert: Search for lines that contain none of the specified substrings.-o, --output OUTPUT: Redirect the output toOUTPUTinstead of printing to standard output. It enables a progress-bar.-s, --substring SUBSTRING: Receive a substring from a command-line argument instead of a file. It can be used multiple times. Must not be used together with the SUBSTRINGS argument.-h, --help: Display the help message and exit.
Arguments
SUBSTRINGS: A file containing substrings to search for. Each line in this file represents a substring to search for.FILE: The file to search in. If not provided, standard input will be used.
Example
- Search in a file for any of the substrings specified in
substrings.txtand write the matching lines tooutput.txt:
findany -o output.txt substrings.txt input.txt
- Case-insensitive search for substrings:
findany -i substrings.txt input.txt
- Read from standard input and write to standard output:
cat input.txt | findany substrings.txt > output.txt
- Read from standard input, write to standard output, pass two substrings via command-line arguments:
findany -s mySubstring -s otherSubstring < input.txt > output.txt
More examples are available in the test cases folder.
License
This program is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.
Metadata
Release files for findany 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| findany-1.2.1.tar.gz | 482.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| findany-1.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 966.1 kB
Release files / findany-1.2.1.tar.gz
| Download URL | findany-1.2.1.tar.gz |
|---|---|
| Size | 482.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32051b1d4fcecd61f11d4ee8a207350fe9ae8482e5fe2f594e770e81402501ac
|
|
BLAKE2b-256 checksum How to use checksums |
e11b97df9ee9f0ec996f412de790e99860ba9b289eaba539b9032f15b4f6c61f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / findany-1.2.1-py3-none-any.whl
| Download URL | findany-1.2.1-py3-none-any.whl |
|---|---|
| Size | 483.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30c8f3db5328addbcf5d4388a66d1f2498bacc9c61fdb99db08d23b0aada78c9
|
|
BLAKE2b-256 checksum How to use checksums |
c47d600d0ef20f83fae7cddd8e20c40cab050fe531fa04c2a8ee16d343bcd440
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|