batch wide find - replace
最后更新:2008-09-09, Ver 2.4.6.0909
简介

bwfr - 支持多国语言的字符串批量查找和替换 - 批量字符集编码转换
|
更新历史

2008-09-09, Ver 2.4.6.0909
2008-09-08, Ver 2.4.5.0908
2008-09-07, Ver 2.4.4.0907
2008-09-06, Ver 2.4.3.0906
2008-08-16, Ver 2.4.1.713
|
所谓 Unicode 正则匹配

bwfr 内部使用完全基于 UNICODE 的高效正则引擎,能够完成各种国际化条件的正则匹配。 以下举例说明:
关于 UNICODE 正则的操作效率,这个引擎比我能找到的所有开源的非 UNICODE 匹配引擎至少快一倍左右(因为所有字符类的匹配都是直接查表映射的,都是标准 O(1) 算法)。 不过这只是匹配引擎的效率,由于所有文件在“匹配->替换”前后都要做一次编码转换,所以典型应用下,wfr 效率比 fr 低一些。wfr 并不是 fr 的升级版,能够用 fr 搞定的任务不推荐用 wfr 完成。 |
关于字符集编码

wfr 支持分别指定三个参量的字符集编码:
例如:“wfr *.txt *.htm -r -argfile:patterns.txt -encarg:big5 -encin:gbk -encout:utf-8 -s” 把当前目录和所有子目录下的任何 txt 及 htm 文件中,满足 patterns.txt 内指定条件的内容全部替换;文件的编码为:gbk,patterns.txt使用 big5 编码,替换后将文件保存为 utf-8 编码。 咋一看指定参数编码好像没用,其实不然。例如在异种语言环境下(如在中文系统下操作韩文)的搜索替换;在DOS下使用wfr(DOS的系统默认代码页永远是ASCII)等场合,指定参数编码是很有意义的。 关于字符集转换功能库,如果当前系统搜索路径中存在 GUN 的 libiconv 库(iconv.dll),则优先使用 libiconv,否则使用操作系统自带的字符集转换 API。这样做的考虑如下:
|
简单中文帮助

C:\Documents and Settings\Administrator> #bwfr =============================================================================== wide find and replace Ver 2.4.1.713 by BaiYang / 2004 - 2008, 免费软件 批量替换版 主页地址 - http://baiy.cn =============================================================================== 在文件或管道中批量搜索-替换字符串——支持多字符集编码 用法: bwfr [文件通配符1 文件通配符2 ...] {查找选项:查找内容} {-argfile:替换规则 文件} [其它选项] =============================================================================== 查找选项: -f: - 匹配精确串 -fic: - 匹配精确串(忽略大小写) -r: - 正则表达式匹配 -ric: - 正则表达式匹配(忽略大小写) -rnnl: - 跨行正则匹配 -rnnlic: - 跨行正则匹配(忽略大小写) =============================================================================== 参数文件选项: 您应当使用参数文件来指定 "查找/替换" 对。参数文件中的每一行代表一个查找替换对, 例如: 1->a 2->b 3->c 4->d ... -argfile:- 指定参数文件路径 -dlm: - 指定查找/替换对中,'查找' 部分和 '替换' 部分之间的分隔符。 默认:"->" 注意: 如果您正在使用正则匹配,那么您可以在“替换”部分中中使用子表达式代换 (\0 ~ \9) 注意:您可以在参数文件中使用系统环境变量,例如: Dir->%SystemRoot% 注意:您可以使用 '\r' 和 '\n' 来表示 '回车符' 和 '换行符',例如: 1->a\r\n 要输出 '\r' 和 '\n' 的字面值,可以使用 '\\r' 和 '\\n'。 =============================================================================== 字符编码选项: -encin: - 指定输入文本(文件或管道)的字符集编码。 默认值: 使用当前操作系统的默认代码页。 -encout: - 指定输出(结果)文本的字符集编码。 默认值: 与 "-encin" 指定的值相同。 -encarg: - 指定参数文件的内容使用何种字符集编码。 默认值: 使用当前操作系统的默认代码页。 -unisign - 如果输出指定为 UNICODE 宽字符编码 (如: UCS-2, UTF-8/16 等), 则在文 件头部加入 BOM 签名,这样支持 unicode 的文本编辑器将会自动识别该文 件的编码格式。 -listenc - 列出所有 bwfr 支持的字符集编码。 -listcmp - 列出 bwfr 认可的键入字符集编码转换规则表。 -force - 强制实施转换,忽略编码兼容性规则。 =============================================================================== 其它选项: -s - 包含子目录 -exp - 启用内存扩展算法,将会加倍 fr 的内存使用量,但是很多时候可以极大地 提高执行效率。如果你碰到了性能问题,可以尝试开启该选项。 -stdin - 从标准输入设备获得要查找的内容,并将结果从到标准输出设备(如果未指 定任何文件模板的话,则自动启用该选项) -stdout - 像平时一样, 从文件中获得输入, 但将结果送到标准输出(而不是写回文 件) -frc - 显示每个文件内发生的替换次数 -trc - 显示所有文件总共发生的替换次数 =============================================================================== POSIX 和 Perl 风格的正则表达式: - "find - replace" 完整支持 POSIX.2 扩展标准及 Perl 风格的正则表达式。 以下是支持的字符类及其对应关系: POSIX perl 描述 -------------------------------------------------------------------- [:alnum:] 字母和数字 [:alpha:] \a 字母 [:lower:] \l 小写字母 [:upper:] \u 大写字母 [:blank:] 空格和制表符 [:space:] \s 空白字符 [:cntrl:] 控制字符 [:digit:] \d 十进制数字 [:xdigit:] \x 十六进制数字 [:graph:] 可打印字符(不包括空白符) [:print:] \p 可打印字符(包括空白符) [:punct:] 标点符号 - 以下是一些 perl 的特殊字符类: perl POSIX等效 描述 -------------------------------------------------------------------- \o [0-7] 八进制数字 \O [^0-7] 非八进制数字 \w [[:alnum:]_] 单词组成 \W [^[:alnum:]_] 非单词组成 \A [^[:alpha:]] 非字母 \L [^[:lower:]] 非小写字母 \U [^[:upper:]] 非大写字母 \S [^[:space:]] 非空白符 \D [^[:digit:]] 非十进制数字 \X [^[:xdigit:]] 非十六进制数字 \P [^[:print:]] 非可打印字符 \< [^[:alpha:]_] 单词开始 \> [^[:alnum:]_] 单词结束 - 注意: posix 字符类是必须工作在集合中的(“[”和“]”内)。相反,perl 风格 的字符类是工作在集合运算之外的。 - 此外,为了便于在命令行输入一些特殊字符,特别定义了一下别名: perl风格 POSIX风格 描述 ----------------------------------------------------------------------- \" [:dq:] 双引号 \' [:sq:] 单引号 \t [:tb:] 制表符 \n [:nl:] 换行符 (0x0A) \r [:rt:] 回车符 (0x0D) \b [:bs:] 退格符 =============================================================================== 开关的前缀和后缀: * 所有命令行开关(选项)都是大小写无关的(如: "-fic:" 和 "-FIC:") * 开关的前缀可以是 "-" 或 "/"(如: "/s" 和 "-s") * 开关的后缀可以是 ":" 或 "="(如: "/f:", "/f=", "-f:" 和 "-f=" 等效) =============================================================================== 应用示例: bwfr *.txt *.htm -fic -argfile:patterns.txt |
帮助屏幕

C:\Documents and Settings\Administrator> #bwfr =============================================================================== wide find and replace Ver 2.4.1.713 by BaiYang / 2004 - 2008, Freeware batch version homepage - http://baiy.cn =============================================================================== Find string in files or pipe, and replace it to another string With Multi- charset encoding support. USAGE: bwfr [filePattern1 filePattern2 ...] {FindOption} {/argfile:} [OtherOptions] =============================================================================== FIND OPTIONs: -f: - find -fic: - find ignore case -r: - regular expresion find -ric: - regular expresion find ignore case -rnnl: - regular expresion find ignore newline -rnnlic: - regular expresion find ignore newline ignore case =============================================================================== ARGUMENTs FILE OPTIONs: You should specify find/replace pairs by an arguments file with an one pair per line semantic. for example: 1->a 2->b 3->c 4->d ... -argfile:- specify the arguments file path -dlm: - specify the delimiter between 'find' part and 'replace' part in a find/replace pair. DEFAULT:"->" NOTE: If find option you specified is a regular expresion method, the replace part will support sub expressions (\0-\9) as well. NOTE: You can use environment variable in arguments file. for example: Dir->%SystemRoot% NOTE: You can use '\r' and '\n' to represent 'return' and 'newline'. for example: 1->a\r\n To produce '\r' and '\n' literally, just type it as '\\r' and '\\n'. =============================================================================== CHARSET ENCODING OPTIONs: -encin: - specify charset encoding for the input text (file or pipe). DEFAULT: use current system's default codepage. -encout: - specify charset encoding for the output text. DEFAULT: same as "-encin". -encarg: - specify charset encoding of the arguments file. DEFAULT: current system's default codepage. -unisign - if the output encoding is unicode (i.e. UCS-2, UTF-8/16, etc.), then add BOM signature to the file. -listenc - list all accepted charset encoding names. -listcmp - list all compatible encoding convertion combination. -force - enforce the text encoding convertion specified by "-encin" and "-encout", even if it is not compatible. =============================================================================== OTHER OPTIONs: -s - include sub folders -exp - enable the memory expand algorithm, will double the memory usage, but MUCH quick in many case. -stdio - get input from standard input device (keyboard and pipe), and put the results to standard output device. default when file pattern is omitted. -stdout - get input from file(s) as normally, but put the results to standard output device. -frc - show File Replacements Count -trc - show Total Replacements Count =============================================================================== POSIX and perl style Regular Expression: - "find - replace" fully support POSIX.2 Extended and Perl style Regular Expresion. Here is a list of they character classes: POSIX perl Description -------------------------------------------------------------------- [:alnum:] letters and digits [:alpha:] \a letters [:lower:] \l lowercase letters [:upper:] \u uppercase letters [:blank:] space and tab characters [:space:] \s whitespace characters [:cntrl:] control characters [:digit:] \d decimal digits [:xdigit:] \x hexadecimal digits [:graph:] printable characters excluding space [:print:] \p printable characters including space [:punct:] punctuation characters - And here a some special char classes in perl: perl POSIX equivalent Description -------------------------------------------------------------------- \o [0-7] octal digit \O [^0-7] non-octal digit \w [[:alnum:]_] word character \W [^[:alnum:]_] non-word character \A [^[:alpha:]] non-alphabetic character \L [^[:lower:]] non-lowercase character \U [^[:upper:]] non-uppercase character \S [^[:space:]] non-whitespace character \D [^[:digit:]] non-digit \X [^[:xdigit:]] non-hex digit \P [^[:print:]] non-printable characters \< [^[:alpha:]_] begin of word \> [^[:alnum:]_] end of word - note: posix char class must working in the square brackets. contrary, perl's must stay outside of the brackets. - And several alias has been created to help input some special char: perl style POSIX style Description ----------------------------------------------------------------------- \" [:dq:] double quotation \' [:sq:] single quotation \t [:tb:] table \n [:nl:] new line (0x0A) \r [:rt:] return (0x0D) \b [:bs:] backspace NOTE: the posix style alias also available on /t, /tu and /tl when using the regex ("/r" and "/ric") match. =============================================================================== SWITCH PREFIX and SUFFIX: * All switchs (options) are case-insensitive (i.e: "-fic:" or "-FIC:") * Switch Prefix can be either "-" or "/" (i.e: "/s" or "-s") * Switch Suffix can be either ":" or "=" (i.e: "/f:", "/f=", "-f:" or "-f=") =============================================================================== EXAMPLEs: bwfr *.txt *.htm -f -argfile:patterns.txt |
字符集编码和转换兼容性

wfr 支持的字符集:使用 -listenc 参数可以查看 wfr 支持的字符集编码列表如下:
字符集编码使用名称或代码页指定均可,并且不区分大小写。
如果用户确实能保证正在进行有意义的转换,可以使用 “/force” 参数要求 wfr 忽略字符集编码兼容性检查。 |
下载
