China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 10:41
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Recommended] A few enhanced regular-expression search and replace tools View 1,397 Replies 7
Original Poster Posted 2010-05-09 10:27 ·  中国 广西 贵港 联通
初级用户
Credits 46
Posts 24
Joined 2006-12-13 23:06
19-year member
UID 73425
Gender Male
Status Offline
Let me recommend a few of Bai Yang's command-line search/replace tools. They're more powerful than CMD's built-in findstr, and also have some advantages over grep. Very useful. I saw them on CCF. Reposting them here as well.
http://www.baiy.cn/

1. Command-line tool f - search for matching strings in files

Feature summary
* Supports specifying multiple file wildcards and file lists at one time.     
* Supports pipe mode, working together with other commands.
* Supports including subdirectories. Unlike grep, even if the search directory itself contains no matching files, it will still continue searching subdirectories.
* Supports ordinary matching, regular-expression matching, case-insensitive matching, and multi-line matching.
* Supports both POSIX standard extended regular expressions and Perl-style regular-expression matching.
* Supports DOS (Windows), Macintosh, and unix-style line endings, with optional automatic detection (default) or manual specification.
* Fully customizable output format for match results, making them easier to view or use together with other software.
* Statistics function, listing the number of matches in each file, total matches, etc.; it can also list only the files where matches were found.
* Supports Win32 and pure DOS environments (pure DOS requires HX DOS Extender support).




Typical uses

1. Use by itself on the command line, or as a pipe filter. For example: "expand -d *.cab | f -ric:g.*.(dll|exe)" searches all cab files in the current directory for dll or exe files beginning with g.  
2. Used in batch files.  
3. Used together with other tools. For example, in vim enter: ":set grepprg=f\ /o:F:l:o" and you can add batch matching capability to vim. Then use the vim command ":grep *.h *.c *.cpp *.hpp *.cxx /s /r:test.*string" to search all source files in the current directory and subdirectories. After that you can use the :cn command to jump to the next match; :cnf jumps to the first match in the next file, and so on.




Quote: Author: lyh728 sed sed also OP's tool, in what way is it stronger than grep?

Well, the feature summary already says it, hehe.
To sum it up, there are probably a few points:
1. When grep searches subdirectories, if the starting directory has no files matching the wildcard, the search stops and it will not check subdirectories. For example: grep -r -i 'test' *.cpp If there are no .cpp files in the current directory, but there are in subdirectories, grep will fail and won't search the subdirectories.
2. Multiple file wildcard support, so you can do this: f *.h *.cpp *.c *.txt /s .... grep seems unable to do that.
3. Some miscellaneous improvements, such as customizable output format and so on.


-----------------------------------------------------------
2. find - replace
fr - batch search and replace matching strings in files

Last updated: 2009-12-13, Ver 2.1.6.1213

* Supports specifying multiple file wildcards and file lists at one time.
* Supports pipe mode, working together with other commands; also supports semi-pipe mode, reading input from files but writing results to standard output.
* Supports including subdirectories.
* Supports ordinary matching, regular-expression matching, case-insensitive matching, and multi-line matching. Replacement can use regular-expression subexpressions.
* Supports TCL 8.2-compatible advanced regular expressions (ARE).
* Supports both POSIX standard extended regular expressions and Perl-style regular-expression matching.
* Can format replacement content as all uppercase or all lowercase, making it convenient in batch files to normalize the case of environment variables and command-line parameters.
* Supports DOS (Windows), Macintosh, and unix-style line endings, with optional automatic detection (default) or manual specification.
* Supports Win32 and pure DOS environments (pure DOS requires HX DOS Extender support).
* Supports POSIX environments, with versions available for linux x86/x64, FreeBSD, NetBSD, Solaris, etc.

------------------------------------------------------------
3. wide find - replace
wfr
  - supports batch search and replacement of multilingual strings
  - batch character-set encoding conversion

Last updated: 2009-12-13, Ver 2.3.6.1213

* A pure unicode rule-matching engine, truly supporting regular-expression matching for text in various languages.
* Supports TCL 8.2-compatible advanced regular expressions (ARE).
* Character-set encoding conversion with compatibility checking. Supports both GUN libiconv (iconv.dll) and the character-set conversion API built into Windows.
* Supports specifying multiple file wildcards and file lists at one time.
* Supports pipe mode, working together with other commands; also supports semi-pipe mode, reading input from files but writing results to standard output.
* Supports including subdirectories.
* Supports ordinary matching, regular-expression matching, case-insensitive matching, and multi-line matching. Replacement can use regular-expression subexpressions.
* Supports both POSIX standard extended regular expressions and Perl-style regular-expression matching.
* Can format replacement content as all uppercase or all lowercase, making it convenient in batch files to normalize the case of environment variables and command-line parameters.
* Supports DOS (Windows), Macintosh, and unix-style line endings, with optional automatic detection (default) or manual specification.
* Statistics function, listing the number of replacements in each file, total replacements, etc.
* Supports Win32 and pure DOS environments (pure DOS requires HX DOS Extender support).
* Supports POSIX environments, with versions available for linux x86/x64, FreeBSD, NetBSD, Solaris, etc.

There are some other command-line tools on the above homepage as well; everyone can look them up as needed.
Floor 2 Posted 2010-05-09 11:33 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
wfr gets killed by a lot of antivirus software, so try to use it as little as possible.
Floor 3 Posted 2010-05-09 11:43 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
No need to post this one, it's been posted many times already.

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 4 Posted 2010-05-09 13:39 ·  中国 广西 贵港 联通
初级用户
Credits 46
Posts 24
Joined 2006-12-13 23:06
19-year member
UID 73425
Gender Male
Status Offline
Originally posted by HAT at 2010-5-9 11:33 AM:
wfr gets killed by a lot of antivirus software, so try to use it as little as possible.

It's just a false positive. The latest antivirus software doesn't report it anymore. Baiyang also says on his homepage that it may be falsely reported. Just unpack it with UPX.
Below is the scan result from the http://virusscan.jotti.org site.
http://virusscan.jotti.org/en/scanresult/f12ff5d43be254442919483a8d13601d248b576c
Attachments
scan.png
Floor 5 Posted 2010-05-09 15:21 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Floor 6 Posted 2010-05-09 16:32 ·  中国 广西 贵港 联通
初级用户
Credits 46
Posts 24
Joined 2006-12-13 23:06
19-year member
UID 73425
Gender Male
Status Offline
They are his works. The name of the poster above looks familiar. Are you Hansing from Hansing's Casual Notes?
Floor 7 Posted 2010-05-09 17:16 ·  柬埔寨
初级用户
★★
Credits 99
Posts 53
Joined 2006-08-18 18:44
19-year member
UID 60809
Status Offline
This tool has been introduced on the forum far too many times. Speaking of regex, OP should really get into SED. Being good with SED is the real way to go.
Floor 8 Posted 2010-05-09 17:43 ·  中国 广西 贵港 联通
初级用户
Credits 46
Posts 24
Joined 2006-12-13 23:06
19-year member
UID 73425
Gender Male
Status Offline
Originally posted by asnahu at 2010-5-9 05:16 PM:
This tool has been introduced on the forum too many times. Speaking of regex, the OP should really get into SED; using SED well is the true king's way.

Thanks for the recommendation and guidance.
I just happened to need to use command-line regex temporarily today, so I only dug this up then. Usually Emeditor is basically enough for me.

After looking up SED commands, they really are powerful. At first glance it gave me a bit of a headache.
I'll take my time and study it when I have some free time later.
Forum Jump: