asgrep is Copyright © 2000-2003 by Ascher Stefan and Danail Traichev.
This program is freeware. You are allowed to use and distribute asgrep for
free, but you are not allowed to sell asgrep for profit. You are using
asgrep at your own risk, no responsibility is taken for damages to your computer
system. The Source Code is provided under the Mozilla Public License, see Appendix C.
asgrep is a Find in Files utility which supports regular expressions (16),
multiple filemasks with wildcards and searches recursively all subfolders if requested. Additionally you
may replace matches with another text with support for escape sequences.
Unfortunately it's not that fast as Borlands Turbo Grep is. Sure, there are sitting
lots of professionals, and I'm just a novice ;-).
This is a console program, i.e. it has no graphical user interface, so you can
easily integrate it in your own program, e.g. as syn does.
19.3 Command line switches
asgrep [-di <folder(s)>] [-fi <filename(s)>] [-ft <findtext>]
[-rt <replacetext>] [-cf <configfile>] [switches]
- -ft: use this switch for the text to find.
- -rt: and -rt for text to replace it with (binary files will be skipped).
- -dt: or -dt to delete found text (binary files will be skipped).
- -fi: before each filename use the switch -fi.
- -di: if you want to search whole directories use -di. If you have set
the r+ switch it will also search all subdirectoreis.
- -ff: for the filefilter use -ff, you can only use one filefilter, you
can also combine more filetilters with wildcards, e.g.
- -cf: you can also use instead of this parameters a configuration file,
use -cf configfile.txt.
- -mc: report match count only.
- r+: for recursive search in directories use r+.
- c+: for casesensitive searche use c+.
- ww+: searching for whole words only.
- re+: use Regular Expression.
- bk-: Don't backup file before replacing text
- es+: use Escape Sequences for Replace text.
- b+: for correct search in binary files.
- b-: to skip binary files from search.
- w+: forces the program to build in some (50 ms) idle time (slower of
- d+: use d+, if you wish to display the line.
19.4 Using a configuration file
If you have a lot of files and/or directories to search, in general when the
command line becomes rather long, you should use a configuration file. This file
is similar to an ini-file:
; The text to look for
; use 1 for match case, otherwise 0.
; Replace the found match with this text
; Do replace the found text with replacetext
; Backup files before replacing
; Replace text contains Escape Sequences
; Search also binary files
; Skip binary files
; Format is either for example "*.htm;*.html" or "*.htm, *.html"
; force the program to wait the specified amount of milliseconds
; before it searches a file
; for recurse search from the given dirs (search all subfolders) use
; searching for whole words only use
; use Regular Expression, can't be combined with wholewords
; Shows only the count of found Matches
; All files you want to search.
; count of the filelist
; All directories you want to search.
All command line arguments are overwritten by the configuration file, except files
and directories, which are added to the list. If an option is not given in the file,
but in the command line, it will use the option from the command line. Should it be so,
shouldn't the command line arguments overwrite the configuration file? Hm, not sure,
give me a hint.
If you replace text, binary files are automatically skipped, because it can't correctly
replace text in binary files. Before you replace text in files you should make a backup copy
of these files.
Matches are written in the console window (StdOut), you can see the filename, the
line and column number and the linetext. One emitted line can look like this, when
you have display lines on, and report match count only off:
D:\Eigene Dateien\hp\download.htm: (72, 87): This program uses the
<a href="http://synedit.sourceforge.net/" target="_blank">SynEdit</a>
The first part is the filename, 72 is the line number, 87 is the
column number, and the last part is the line text:
FileName: (line number, Column Number): Line text.
19.6 Replace text
It is possible to replace found matches with another text. To do so, provide the
-rt switch followed by the new text. If your replace text contains escape
sequences (17), and you wish to substitute them by the
corresponding character provide also the
es+ switch. If you additionally
bk- switch it does not backup files before replacing text in them.
The Regular Expression code is taken from Andrey V. Sorokin's
TRegExpr Unit (http://anso.da.ru/).