中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 16:30
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Recommended] A few enhanced regular-expression search and replace tools
Printable Version  1,399 / 7
Floor1 fastrun Posted 2010-05-09 10:27
初级用户 Posts 24 Credits 46
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




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.
Floor2 HAT Posted 2010-05-09 11:33
版主 Posts 5,017 Credits 9,023
wfr gets killed by a lot of antivirus software, so try to use it as little as possible.
Floor3 yishanju Posted 2010-05-09 11:43
银牌会员 Posts 1,357 Credits 1,488
No need to post this one, it's been posted many times already.
Floor4 fastrun Posted 2010-05-09 13:39
初级用户 Posts 24 Credits 46
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 (85.66 KiB)
Floor5 Hanyeguxing Posted 2010-05-09 15:21
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
What do you mean by Bai Yang's?
Floor6 fastrun Posted 2010-05-09 16:32
初级用户 Posts 24 Credits 46
They are his works. The name of the poster above looks familiar. Are you Hansing from Hansing's Casual Notes?
Floor7 asnahu Posted 2010-05-09 17:16
初级用户 Posts 53 Credits 99
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.
Floor8 fastrun Posted 2010-05-09 17:43
初级用户 Posts 24 Credits 46
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.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023