Skip to main content

A command line tool for searching multiple substrings in a multiline text file

Project description

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.
  • 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

  1. Download the latest release from the Releases page.
  2. Save it to any folder (e.g. /usr/local/bin/ or C:\Users\<user>\AppData\Local\), add that folder to the PATH variable.
  3. 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 to OUTPUT instead 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

  1. Search in a file for any of the substrings specified in substrings.txt and write the matching lines to output.txt:
findany -o output.txt substrings.txt input.txt
  1. Case-insensitive search for substrings:
findany -i substrings.txt input.txt
  1. Read from standard input and write to standard output:
cat input.txt | findany substrings.txt > output.txt
  1. Read from standard input, write to standard output, pass two substrings via command-line arguments:
findany -s mySubstring -s otherSubstring < input.txt > output.txt

License

This program is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.

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

findany-1.1.3.tar.gz (125.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

findany-1.1.3-py3-none-any.whl (125.1 kB view details)

Uploaded Python 3

File details

Details for the file findany-1.1.3.tar.gz.

File metadata

  • Download URL: findany-1.1.3.tar.gz
  • Upload date:
  • Size: 125.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for findany-1.1.3.tar.gz
Algorithm Hash digest
SHA256 b017e28e0b466bf4dd08f21806cc48776d1fbe265a1f505ac0286433ce6cb546
MD5 b934d23453dd85b24b1e08d0b513c2af
BLAKE2b-256 5929f5c029c190d8d65bfa952c94ff438b4b98fcfb5273392e60fe61a94eea84

See more details on using hashes here.

File details

Details for the file findany-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: findany-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 125.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for findany-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9812298183a25228ce8d1882d6ae6495b2af8245294aea0cdbe45199d90be2cb
MD5 04b8b5c2e7d4b981e34fcda12ccd1622
BLAKE2b-256 01b8adcc0045e37d41688223fe2f87d15b25f1fe0f99d362205dd0f8cc08f0f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page