The algorithm used is a variation of the Boyer-Moore search algorithm, modified to search binary files. As a result of this, gsar is blindingly fast.
Opposed to line oriented search programs (like grep(1) ), gsar will find all matches on a line. Actually, gsar doesn't know anything about lines at all, all files and strings are treated as binary.
Gsar can search one or several files for a string and report the occurrences. Gsar can read one file, search for a string, replace it with some other string, and create a new file containing the changes. Gsar can perform a search and replace in multiple files, overwriting the originals. Finally, gsar can work as a filter, reading from standard input and writing to standard output.
An option which takes an argument must be the last one in the concatenated option, since the rest of the option is taken as a possible argument.
Fields enclosed in [] are optional, but mandatory when enclosed in <>. Options are case sensitive i.e -b is not the same as -B .
If no options are given, gsar just gives a brief help message.
Example: To
search for the string :foo (`o' is 111 decimal, 6F in hex) use the search
options:
-s::foo or -s::fo:111 or -s::fo:x6F
If you want to search for a string with spaces in it, under MSDOS surround the expression with quotes. Under Unix, use the mechanisms your shell provides (commonly quotes) to include space or other special characters.
Example: search for gsar is fast use:
gsar "-sgsar is fast" foobar.txt
The precompiled MSDOS executable in the archive supports response files. Just put you gsar commands into a file and put a `@' in front of the filename on the gsar command line.
Example:
file foobar.txt contains -ssupercalifragilisticexpialidocus :
gsar @foobar.txt poppins.txt
If response files are needed, most Unix
shells will allow
gsar `cat foobar.txt` poppins.txt
Example:
gsar -s__ZTC__ -r__TURBOC__ -o foo.c bar.c bat.c
The files foo.c , bar.c & bat.c are all changed.
gsar -s:x20:x20:x0d -r:x0d -o foobar.txt *.c
Convert a UNIX text file to DOS format overwriting the original file:
gsar -ud -o unix.txt
Search for the string WATCOM and replace with __ZTC__ using gsar as a filter. Output is redirected to a new file:
gsar -sWATCOM -r__ZTC__ -F < foo_w.c > foo_z.c
Display textual context of the string error in the file gsar.exe disregarding case. With 40 bytes in the context:
gsar -serror -i -c40 gsar.exe
Search for the string gnu in the file fsf and replace it with wildebeest , creating a new output file africa :
gsar -sgnu -rwildebeest fsf africa
(if the file africa exists, you have to use the -f option to overwrite it.)
Search for the string error in the file command.com and display the byte offset of each match:
gsar -serror -b command.com
On MSDOS platforms stdin from a tty is not allowed because stdin has been turned into binary. MSDOS will not catch the Ctrl-Z signifying EOF.
If you have any comments, bug reports or whatever, we can be reached through email at:
tormod@sn.no
hpv@kjemi.uio.no