在目录路径中搜索任何字符串列表。

string-path-search的Python项目详细描述


字符串路径搜索

遍历目录树,搜索包含任何一组文本字符串的文件。

注意:python结果中github vs包上项目的不同命名约定 在一些不必要的混乱中:“string path search”(带连字符)是 github。此项目提供“string_path_search”(带下划线)python包。 请容忍我。

为什么不直接使用findgrep

  • 避免使用大量的反勾号和括号来调试长而难的shell命令。
  • 在windows上工作,不需要安装类似于cygwin的unix。
  • 一次搜索一堆不同的字符串。
  • 在(可能是压缩的)jar、tar或zip档案中搜索。
  • 以csv或excel格式输出结果。

系统要求

  • 在Windows10、Linux和Windows10/cygwin上测试。也可以在其他平台上工作 由python支持。
  • python 3.4或更高版本(https://www.python.org/downloads/)。
  • 适用于已安装的python版本的python pip模块 (https://pip.pypa.io/en/stable/installing/)。安装python包是可能的, 包括字符串路径搜索,没有pip,但是没有它会困难得多。

关于安装python和pip的说明

一些linux系统(在windows上也是cygwin)附带python 2 预安装。你必须自己安装python 3。有问题 涉及:

  1. “python”和“pip”包可以为版本2保留。这可能不像 “apt get install python3”也可以。最新的软件包可能被称为“python3.7”或类似的软件包。 和皮普一样。
  2. 一旦安装,python3二进制文件就可以称为“python3”,而不是 “Python”。和皮普一样。

从PYPI安装:

> python -m pip install --user string-path-search 

从Github安装

您还可以使用浏览器下载字符串路径搜索作为.zip或.tgz存档 https://github.com/j-lawrence-b1/string-path-search/releases/latest 任何方便的目录。解包后,可以安装字符串路径搜索及其 使用附带的setup.py脚本(在内部使用pip!).

> chdir <my-downloads-dir>\\string-path-search-0.3.2
> python setup.py build install --user 

注意:使用“--user”选项安装将安装字符串路径搜索python包 在登录的主目录下(c:/user s/<;user name>;/.local/scripts on windows或/home/<;用户名>;/.local/bin(Linux上)。如果你打算运行 如果直接提供string_path_search.exe,则应将此目录添加到 你的外壳的执行路径。

用法

尽管可以在其他python脚本中导入和使用此包, 字符串路径搜索主要用作控制台应用程序:

    $ python -m string_path_search [OPTIONS] <scan-root> [<search-term> [...]]

或者,您可以直接添加并运行独立的string_path_search.exe(请参见上面的note,)。

    $ ~/.local/bin/string_path_search [OPTIONS] <scan-root> [<search-term> [...]]

其中:

    -a, --scan-archives = Unpack and scan within archives
        (Default: Skip arhive files. Only jar, tar, and zip archives will be
            unpacked. Tar bzip2, gzip, and xz compression is supported.
    -B, --branding-text=<branding-text> = A string of text containing
        company or other information to add above the column headers in
        scan reports (Default: no text).
    -b, --branding-logo=<branding-logo> = (MS Excel only) An image
        file containing a corporate logo or other graphic to add above the
        column headers in scan reports (Default: no logo).
    -h, --help = Print usage information and exit.
    -e, --excel-output = Generate Microsoft Excel 2007 (.xlsx) output
        (Default: Generate comma-separated-value (CSV) text output)
    -i  --ingore-case = Ignore UPPER/lowercase differences when matching strings
        (Default: case differences are significant).
    -o, --output-dir=<output-dir> = Location for output (Default:
        <current working directory>).
    -s, --search-strings-file=<search-strings> = A file containing strings to
        search for, one per line (Default: Get search strings from the command line).
    -q, --quiet = Decrease logging verbosity (may repeat). -qqqq will suppress all logging.
    -t, --temp-dir=<temp-dir> = Location for unpacking archives
        (Default: <output_dir>/temp).
    -v, --verbose = Increase logging verbosity.
    -x, --exclusions-file=<exclusion-file> = A file containing (base) filenames to
        exclude from the search results, one per line (Default: Include all results).
<scan-root> = Directory to scan.
<search-term> ... = One or more terms to search for in <scan-root>.

示例

对test/data目录执行无案例搜索,以查找 “copyright”、“gpl”、“foo”、“bar”或“baz”,并将结果输出到 当前工作目录中名为“scan-<;timestamp>;.csv”的文件。

$ python -m string_path_search -i tests/data "copyright (c)" gpl foo bar baz

与示例1相同,只是输出到Excel电子表格:

$ python -m string_path_search -i -e tests/data "copyright (c)" gpl foo bar baz

gotcha:对多词搜索字符串使用双引号。不知为什么, 单引号会破坏命令行解析器。

许可证

字符串路径搜索分布在 MIT License

关于测试数据的免责声明:

测试/数据文件夹中的文件是从 可用的开源项目。以字符串路径搜索方式分发这些材料 测试数据可能违反或不违反适用的许可证。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Android Java在活动之间传递值   java当实体中存在关系时,我可以只使用实体的id而不是从DB中获取实体吗?   bouncycastle Java运行SSHD服务器错误未找到类定义   java SWT/Swing>Threads n'Hell   java多线程数据库读取   java如何在Eclipse中轻松提交Git   java在哪里可以找到字符串相等比较的一组特定排序规则?   无连接表的java单向单域关系   java扩展三角文件   java spring。杰克逊。序列化。failonemptybeans   java无法加载请求的类:oracle。jdbc。驾驶员OracleDriver   java通过数组进行索引循环并打印出元素?   找不到eclipse错误类中的java提交Hadoop作业   Java:随机设定种子   java片段、异步任务和侦听器   java在分号后使用{}