PYF:程序员的发现

pyf-programmers-find的Python项目详细描述


它的发音是“pif”。

pyf [options][search-pattern [filename-pattern [start-directory]]]

递归搜索其内容与搜索模式匹配的文件。

  • (可选)将搜索限制为名称匹配的文件 文件名模式。
  • (可选)chdir在开始搜索之前启动目录。
  • 模式是python正则表达式。

因为我厌倦了写作而写作:

find . -name '*.py' -exec egrep -l regex {}\;

上面的PYF是:

pyf regex '\.py$'

pyf regex 'py$'

或者只是

pyf regex py

如果不将regex作为文件名模式传入,pyf假定它是 文件扩展名匹配,并在末尾添加$。

文件名模式和文件内部的搜索模式都是 Python regular expressions

示例

查找包含regex

的文件
pyf regex

上面的示例将递归地查找文件并在 文件。

将搜索限制为某些文件扩展名

pyf regex py

上面的示例将递归地查找名称以“py”结尾的文件 并在文件中搜索“regex”。

查找包含一个内容但不包含另一个内容的文件

pyf post html | pyf -v -f - csrf_token

上面查找名称以“html”结尾并包含“post”但 不包含“csrf\u令牌”。

在匹配的文件上运行命令

pyf -r "sed -i '' -e 's/yajogo\.core\.debug/yajogo.core.logging/g'"'yajogo\.core\.debug' py

上面查找扩展名为“py”且包含字符串的文件 “yajogo.core.debug”并对其运行sed命令。

打印regex匹配项

pyf -s -m '\d+x\d+' html

上面将在其名称为的文件中打印模式“+x+”的所有匹配项 以“html”结尾。-s选项禁止打印 比赛。m选项将导致打印匹配的正则表达式。所以, 使用上面的命令,您可能会得到如下输出:

57x57
72x72
114x114
512x512
200x200
150x150
150x150
150x150
500x500
800x600
150x150
150x150

我们可以把这个命令的输出通过管道传送到另一个程序。为了 示例:

pyf -s -m html '(\d+x\d+)'| sort | uniq

会给我们一个排序的唯一匹配列表:

114x114
150x150
200x200
500x500
512x512
57x57
72x72
800x600

安装

pip install pyf-programmers-find

用法

$ pyf -h
usage: pyf [options][search-pattern [filename-pattern [start-directory]]]

pyf: programmers find

Recursively search for files whose contents matches search-pattern.
Optionally restrict the search to files whose name matches filename-pattern.
Patterns are Python regular expressions.

It's pronounced "pif".

positional arguments:
  search-pattern        Match this pattern in files.
  filename-pattern      Only search files whose name matches this pattern.
  start-directory       Change to this directory before findind and searching
                        files.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --debug               Turn on debug logging.
  --debug-log FILE      Save debug logging to FILE.
  -c COUNT, --context COUNT
                        Show COUNT surrounding context lines of the matches.
                        Only makes sense when printing matched lines with the
                        -p option. Default 0.
  -d START_DIRECTORY, --chdir START_DIRECTORY
                        Change to directory START_DIRECTORY before starting
                        the search. Can also be given as the third positional
                        argument.
  -e SEARCH_PATTERN, --regexp SEARCH_PATTERN
                        Use SEARCH_PATTERN as the pattern to match in a file;
                        use when defining patterns beginning with -. Can also
                        be given as the first positional argument.
  -f FILE, --file FILE  File to search for a match. Instead of recursively
                        searching all files. Can be given multiple times. If
                        argument is - reads a list of files to match from
                        stdin.
  -i, --ignore-case     Ignore case. Default False.
  -l, --line-number     Print the matching line number. Default False.
  -m, --matches         Print the matching regex group. Default False.
  -n FILENAME_PATTERN, --filename FILENAME_PATTERN
                        Recursively find files whose name matches
                        FILENAME_PATTERN. Only search in those files. Can also
                        be given as the second positional argument. Default:
                        .+
  -p, --print-lines     Print the matching line. Default False.
  -r CMD, --run CMD     Run a program CMD for each matching file, passing the
                        path name of the matching file as an argument. Ignored
                        if the -p or -l options are given.
  -s, --no-filename     Do not print the file name when printing matched
                        lines. Only makes sense with the -p option. Default
                        False.
  -v, --invert-match    Invert the sense of the match. Print non-matching
                        files and lines. Default False.
  -A, --suppress-file-access-errors
                        Do not print file/directory access errors.
  -B, --no-binary-check
                        Ignore (heuristic) binary file check, do not skip
                        probably binary files.
  -N, --no-pager        Do not pipe output to a pager when stdout it detected
                        as a tty.
  --force-pager         Always try to pipe output to a pager, do not check if
                        stdout is a tty. Ignored when running with the -r
                        option.
  --skip-dirs-pattern SKIP_DIRS_PATTERN
                        Regex of directories to skip. Default
                        '(^\..+|CVS|RCS|__pycache__)'.
  --skip-files-pattern SKIP_FILES_PATTERN
                        Regex of files to skip. Default '(^\..+|\.pyc$)'.

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

推荐PyPI第三方库


热门话题
java如何用jsoup解析span title?   集合Java不可修改集强制转换为枚举集   编译器构造在编译时禁用Java中的日志记录   Java中基于等式的哈希代码生成   获取所有子节点和值的java XPath   java添加到ArrayList问题   java HttpClientErrorException$禁止:403:Rest模板Spring Jersey   java如何从字符串传递到字符   java从Liferay开始,对如何开始有些不知所措   odt中的Java Open\LibreOffice插入文件\对象   java意外循环出现   java如何从resultset获取单行   java FirebaseAuth。getInstance()。signOut()不会注销   java如何更改JFrame的大小?   eclipse如何在Java源代码中使用TikaCLI功能?   如何验证用户输入的字符串?(爪哇)   java不正确?