reprec:递归地替换文件和其他文件中的字符串

reprec的Python项目详细描述


https://travis-ci.org/guettli/reprec.svg?branch=master

reprec:递归地替换文件和其他内容中的字符串

文本文件的命令行工具。

https://github.com/guettli/reprec

工具

目前有以下工具:

  • reprec: Replace strings in text files. Can work recursive in a directory tree
  • setops: Set operations (union, intersection, …) for line based files.

重复记录

reprec工具替换文本文件中的字符串:

===> reprec --help
Usage: reprec
         [-p|--pattern] p
         [-i|--insert] i
         [-f|--filename regex]
         [-n|--no-regex]
         [-v|--verbose]
         [-a|--ask]
         [--print-lines]
         [--dotall]
         [--ignorecase]
         [--novcexclude]
         [--files-from file|-]
         [--ignore regex]

         dirs

    dirs:        Directories or files for replacing. Use is '.' for current dir.

    pattern:     Regex pattern.

    insert:      Text which gets inserted

    filename:    Regex matching the filename. E.g. '.*\.py'

    no-regex:    Normal string replacement will be used.
                 This means you can use '.', '*', '[' without quoting

    verbose:     Print the number of changes for each file

    print-lines: Print the old and the new line for each change.
                 Not available if --dotall is used.

    dotall:      In regular expressions '.' matches newlines, too.
                 Not supported with --ask and --print-lines.

    ignorecase:  ...

    novcexclude: Don't exclude the directories called '.svn' or 'CVS'.
                 By default they get ignored.

    ask:         Aks before replacing (interactive).

    files-from:  Read filenames from file or stdin if '-'.
                 Skip directories.

    ignore:      Ignore lines that match a regular expression.
                 This options can be given several times.

    Example:
     reprec --pattern '(xml)' --insert '\1\1' .
     -->This will replace all 'xml' with 'xmlxml'

     Or, shorter:
     reprec '(xml)' '\1\1'

    Example2:
     find -mtime -1 -name '*.py' | reprec --files-from=- foo bar


    The Perl Compatible Regular Expresssions are explained here:
      http://docs.python.org/lib/re-syntax.html

    The files are created by moving (os.rename()) FILE_RANDOMINTEGER
    to FILE. This way no half written files will be left, if the
    process gets killed. If the process gets killed one FILE_RANDOMINTEGER
    may be left in the filesystem.

设置操作

工具setops为基于行的文件提供设置操作(并集、交集等):

usage: setops [-h] set1 operator set2

Operators:
  union Aliases: | + or
  intersection Aliases: & and
  difference Aliases: - minus
  symmetric_difference Aliases: ^

Examples

#Show all files in directory "a" which are not in directory "b":
setops <(cd a; find ) - <(cd b; find )

# Create some files for testing
echo foo > foo.txt
echo bar > bar.txt
echo foobar > foobar.txt

# All files minus files containing "foo"
user@host$ setops <(ls *.txt) - <(grep -l foo *.txt)

# All files containing "foo" or "bar" minus files which contain "foobar"
setops <(setops <(grep -l bar *.txt) + <(grep -l foo *.txt)) - <(grep -l foobar *.txt)



positional arguments:
  set1
  operator
  set2

optional arguments:
  -h, --help  show this help message and exit

安装

pypi安装:

pip install reprec

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

推荐PyPI第三方库


热门话题
virtualbox无法从java移动共享文件夹中的文件   java如何连接Android 4.3.5(GA)的apache HttpClient库?   片段中的java Recyclerview未立即显示警报对话框结果   javac(n,r)计算器程序不工作   java使用BooleanQuery还是编写更多索引?   如何在java中设置y/n循环?   java不兼容的通用通配符捕获   java如何在安卓xml中编写数据绑定时的三元操作条件   java如何使用FileDialog?   java如何创建单元测试来检测是否有人使用错误的编码编辑了文件?   java如何从唯一的字符串生成唯一的int?   java gradletomcatplugin:log4j:WARN找不到记录器的附加程序   java我的动态编程解决方案(Kefa和第一步)在codeforces中有什么问题?   java每天更新两个数据库,使它们都包含相同的有效数据集   java如何检查给定的时间是否在时间限制之间   java在单个json POST上保存父级和子级   java如何获取Solr字段类型