Previous Up Next

19  asgrep

19.1  License

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.

19.2  Introduction

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]

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:
[main]
; The text to look for
findtext=yourfindtext
; use 1 for match case, otherwise 0.
matchcase=1
; Replace the found match with this text
replacetext=yourreplacetext
; Do replace the found text with replacetext
doreplace=0
; Backup files before replacing
backup=1
; Replace text contains Escape Sequences
escapeseq=0
; Search also binary files
checkbinary=0
; Skip binary files
skipbinary=0
; Format is either for example "*.htm;*.html" or "*.htm, *.html"
filefilter=*.*
; force the program to wait the specified amount of milliseconds
; before it searches a file
idle=50
; for recurse search from the given dirs (search all subfolders) use
recurse=1
; searching for whole words only use
wholewords=1
; use Regular Expression, can't be combined with wholewords
regexp=1
; Shows only the count of found Matches
matchcount=1

[files]
; All files you want to search.
count=2
; count of the filelist
1=D:\1stFile.txt
2=D:\2ndFile.txt
; ...

[dirs]
; All directories you want to search.
count=2
1=1stDir
2=2ndDir
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.

19.5  Results

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 use the bk- switch it does not backup files before replacing text in them.

19.7  Credits




Previous Up Next