home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / packet / bis_v20.arc / FGREP.DOC < prev    next >
Text File  |  1988-06-15  |  14KB  |  350 lines

  1.                                   fgrep 1.62
  2.                                   ----------
  3.  
  4.         "|" denotes items that are new/changed in the recent versions.
  5.  
  6.  
  7.         Purpose
  8.         -------
  9.  
  10.         Fgrep (Fast GREP) is a small utility that can be used to find
  11.         strings of characters in ASCII text files.  String search
  12.         capabilities are not extensive (no regular expressions), but
  13.         fgrep is small and very, very fast.  Fgrep is intended to
  14.         replace DOS's FIND filter with something faster and more
  15.         flexible.
  16.  
  17.         UNIX people:  we fully realize that this isn't the grep or fgrep
  18.         with which you are familiar.  We know that the RE in GREP means
  19.         "regular expressions" and we know that we don't support regular
  20.         expressions.  However, the name serves to point people in the
  21.         right direction.  Please don't write to tell us that this "isn't
  22.         really grep".
  23.  
  24.  
  25.         Using fgrep
  26.         -----------
  27.  
  28.         Fgrep's syntax is
  29.  
  30.                 fgrep [-aceflmopsvwx01] target {file}
  31.  
  32.         The -switches are discussed below.
  33.  
  34.         The target is the string of characters for which you are
  35.         searching.  It may need to be bracketed by a pair of
  36.         non-alphanumeric delimiters.  The target should be delimited if:
  37.  
  38.             -- it contains spaces or tabs
  39.             -- it begins with a non-alphanumeric character
  40.             -- it contains the DOS redirection characters < > |.
  41.  
  42.         In the last case, the string MUST be delimited by double quotes
  43.         ("), otherwise DOS will interpret it as redirection.
  44.  
  45.         Examples of targets:
  46.  
  47.                 mov
  48.                 ax
  49.                 /mov ax/        (contains a space)
  50.                 '/7'            (begins with non-alphanumeric)
  51.                 "f->x"          (contains ">", must use double quotes)
  52.  
  53.         It is always OK to delimit a string, even if delimiters are
  54.         unnecessary.
  55.  
  56.         If the target contains DOS redirection characters (<, >, or |),
  57.         it MUST be delimited with double quotes ("") or DOS will try to
  58.         perform unwanted redirection.  For example:
  59.  
  60.             fgrep "a<=b" myfile.pas
  61.  
  62.         The string may include one or more "?" wildcards.  The ? will
  63.         match any single non-null character in the file.  E.g., "[?i]"
  64.         will match "[si]", "[di]", etc., but not "[i]".
  65.  
  66.         The list of files may include wild cards.  Here are some
  67.         examples of fgrep use:
  68.  
  69.                 fgrep  -c  "include foo.c"  *.c
  70.                 fgrep abcd? filea.ext fileb.ext filec.ext
  71.                 fgrep -1f 'call fido' a:\masm\*.asm  b:*.asm
  72.                 fgrep ax *.asm
  73.  
  74.         If no file is specified, input will be taken from standard
  75.         input, allowing redirection and piping.  For example:
  76.  
  77.                 arc p somefile foo.txt | fgrep somestring
  78.  
  79.         will display occurrences of "somestring" in the file archived as
  80.         foo.txt in somefile.arc.
  81.  
  82.  
  83.         Output
  84.         ------
  85.  
  86.         Fgrep's default screen output looks like this:
  87.  
  88.                 **File <filename>
  89.                 [text of lines containing string]
  90.                 **File <filename>
  91.                 [text of lines containing string]
  92.  
  93.       | If the "Microsoft" (-M) switch is used, the output is in this
  94.       | format:
  95.       |
  96.       |         FILE.EXT(linenum): text
  97.       |
  98.       | This format is the standard format used by Microsoft (R)
  99.       | language products and by its MEGREP.
  100.  
  101.         All useful output is sent to the standard output device, so it
  102.         may be piped to other programs or redirected to file:
  103.  
  104.                 fgrep target filea | yourprog
  105.                 fgrep target filea > test.txt
  106.  
  107.         Error messages and the program logo will appear always appear on
  108.         the console device, and will never appear in redirected or piped
  109.         output.
  110.  
  111.         Fgrep always returns an errorlevel to the operating system.  It
  112.         will be one of:
  113.  
  114.             0:   String not found in any file
  115.             1:   String found in at least one file
  116.             255: Error (file read error or bad parameter)
  117.  
  118.  
  119.         Switches
  120.         --------
  121.  
  122.         -A is ANSI mode.  If you have ANSI.SYS (or equivalent)
  123.            installed, escape characters (ASCII 27) in displayed text
  124.            lines can cause odd results.  If you use the -A switch,
  125.            FGREP will substitute an upside-down question mark (¿) for
  126.            ESC, possibly resulting in cleaner displays.  You'll only
  127.            need this switch if you have ANSI installed and there are ESC
  128.            characters in the files you're scanning.
  129.  
  130.         -C makes the search case sensitive ("String" will not match
  131.            "string" or "STRING").  Normally, fgrep ignores case.
  132.  
  133.         -E specifies that ONLY an errorlevel is to be returned.
  134.            There will be no display at all.  This is equivalent to the
  135.            combination -s0.
  136.  
  137.         -F causes the "**File" header lines to be displayed only for
  138.            those files that contain the search string.
  139.  
  140.         -L adds line numbers to fgrep's output.
  141.  
  142.         -M specifies Microsoft (R) output format.  See "Output" above.
  143.  
  144.         -O specifies a maximum output width.  It should be followed by a
  145.            decimal number from 1 to 255.  For example, -O40 causes fgrep
  146.            to truncate all output to a maximum of 40 characters per
  147.            line.  Do not confuse the "O" (Output) switch with the "0"
  148.            (zero text) switch.
  149.  
  150.         -P pauses on full screen of output
  151.  
  152.         -S suppresses the "**File" header lines in the output.
  153.  
  154.         -V provides a reVerse or negative search.  That is, all lines
  155.            that do NOT contain the specified string are displayed.  This
  156.            provides a handy way to get rid of lines containing specified
  157.            text.  Suppose, for example, that you have a file containing
  158.            a list of file names, and you are interested in all files
  159.            EXCEPT those that contain a '$' in the name (perhaps they are
  160.            temporary files):
  161.  
  162.                 fgrep -v "$" filename
  163.  
  164.         -W switch indicates that white space (blanks and tabs) is not
  165.            significant.  White space in both the search string and the
  166.            input file will be ignored.  If -w is specified, the wildcard
  167.            character (?) will match any nonblank character.
  168.  
  169.         -X Do not display the logo/copyright.
  170.  
  171.         -0 ("0" text lines) suppresses the display of lines of text
  172.            containing the specified string.  Fgrep will skip immediately
  173.            to the next file when the string is found.  Do not confuse
  174.            this with the "O" (Output width) switch.
  175.  
  176.         -1 ("1" text line) specifies that only the first line containing
  177.            containing the specified string in each file will be
  178.            displayed.  Fgrep will then skip immediately to the next
  179.            file.
  180.  
  181.  
  182.         "Fast" search algorithm
  183.         -----------------------
  184.  
  185.         Beginning with version 1.55, a new and faster technique is used
  186.         for some searches.  This algorithm will NOT be used if:
  187.  
  188.       |     - line numbers or Microsoft (R) format used (-L or -M)
  189.             - the search is reVerse (-V)
  190.             - the search is whitespace insensitive (-W)
  191.             - the target string contains wildcards ("?")
  192.  
  193.         For other searches, the new technique is typically 20-40% faster
  194.         than the old, although we've seen 70% improvements in some
  195.         cases.  One tester reported that fgrep located a string in the
  196.         last line of a 440K file in 0.97 seconds (IBM AT).
  197.  
  198.         The technique has its roots in searching for unusual (less
  199.         frequently used) characters, so it will make more of a
  200.         difference searching for "squeeze" (q is a little-used letter)
  201.         than it will searching for "eat".
  202.  
  203.         When fgrep can use the fast technique, input lines are not
  204.         limited to 500 characters (as they have been with past
  205.         versions).
  206.  
  207.         Notes
  208.         -----
  209.  
  210.         1. The -f and -s switches are mutually exclusive.  If both are
  211.         specified, the last one will be effective.
  212.  
  213.         2. If you specify the -e switch, fgrep will stop processing as
  214.         soon as a nonzero errorlevel is determined.  The -e switch is
  215.         really designed to enable other programs to determine whether or
  216.         not a specific file contains a specific string in as little time
  217.         as possible.  For example, here's an algorithm that will quickly
  218.         'touch' all files that do NOT contain a specified string:
  219.  
  220.                 for file in (*.*) do
  221.                     fgrep -e string file
  222.                     if errorlevel < 1 then touch file
  223.                 end
  224.  
  225.         3. The -s switch is automatically set when input is taken from
  226.         standard input.
  227.  
  228.         4. Fgrep optimizes the combination -s0 (suppress headers, no
  229.         text) to a -e.
  230.  
  231.         5. If you just want to know which files contain a string, use -0;
  232.         it saves time because the rest of the file (after the first hit)
  233.         is skipped.  The combination -0f is particularly efficient
  234.         for this as it will simply display a list of files that contain
  235.         the string.
  236.  
  237.      |  6. If any of the -V, -W, -L, or -M switches are used, or if the
  238.         target contains wildcards, input lines are limited to a maximum
  239.      |  length of 500 characters (if you use a -w search, spaces don't
  240.         count).  Fgrep expects standard text files; binary files will
  241.         yield weird results.  Word processor files may or may not work,
  242.         depending on how they are formatted.  Lines can be terminated by
  243.         any of CR, LF, or CR+LF.
  244.  
  245.         7. If output is redirected to disk, make sure there is enough
  246.         space available.  The program does not check.
  247.  
  248.  
  249.         Version 1.62
  250.         ------------
  251.         Added -M switch.
  252.         Increased max length of lines ("slow" search) from 256 to 500.
  253.  
  254.         Version 1.61
  255.         ------------
  256.         Fixed a problem with pausing on > 255 hits (-P not specified).
  257.  
  258.         Version 1.60
  259.         ------------
  260.         Added -P switch.
  261.         Fixed a problem with tab characters and -O switch.
  262.  
  263.         Version 1.59
  264.         ------------
  265.         Added -O switch.
  266.         Altered -L operations to allow for line numbers > 65535.  Line
  267.         numbers now right justified in a 6-character field.
  268.  
  269.         Version 1.58
  270.         ------------
  271.         Fixed two problems that were causing endless loops in 1.55-1.57.
  272.         Added -A switch.
  273.  
  274.         Version 1.57
  275.         ------------
  276.         Added -X switch.
  277.  
  278.         Versions 1.55/1.56
  279.         -----------------
  280.         "Fast" search algorithm added (thanks to Dave Angel for the
  281.         idea and the shove).
  282.  
  283.         Fixed problems with redirected input.
  284.  
  285.         Forced -v (reVerse) search to show blank lines.
  286.  
  287.         Versions 1.50/1.51
  288.         ------------------
  289.         These versions contain no new features but are significantly
  290.         faster than earlier versions.  Standard (case-insensitive)
  291.         searches run about 40% faster than 1.45 (which was 25-30%
  292.         faster than 1.40).  "Literal" searches (case-sensitive and
  293.         spacing-sensitive) are highly optimized and may be as much as
  294.         70% faster than 1.45.
  295.  
  296.         Version 1.45
  297.         ------------
  298.         We found a few areas that could be made more efficient.  This
  299.         version can be as much as 25-30% faster than version 1.40.
  300.  
  301.         The -L (line numbers) option was added, and improvements made to
  302.         parameter parsing such that delimiters are not always necessary.
  303.  
  304.  
  305.         Copyright/License/Warranty
  306.         --------------------------
  307.  
  308.         This document and the program file FGREP.COM ("the software")
  309.         are copyrighted by the author.  The copyright owner hereby
  310.         licenses you to: use the software; make as many copies of the
  311.         program and documentation as you wish; give such copies to
  312.         anyone; and distribute the software and documentation via
  313.         electronic means.  There is no charge for any of the above.
  314.  
  315.         However, you are specifically prohibited from charging, or
  316.         requesting donations, for any such copies, however made; and
  317.         from distributing the software and/or documentation with
  318.         commercial products without prior permission.  An exception is
  319.         granted to not-for-profit user's groups, which are authorized to
  320.         charge a small fee (not to exceed $7) for materials, handling,
  321.         postage, and general overhead.  NO FOR-PROFIT ORGANIZATION IS
  322.         AUTHORIZED TO CHARGE ANY AMOUNT FOR DISTRIBUTION OF COPIES OF
  323.         THE SOFTWARE OR DOCUMENTATION, OR TO INCLUDE COPIES OF THE
  324.         SOFTWARE OR DOCUMENTATION WITH SALES OF THEIR OWN PRODUCTS.
  325.  
  326.         THIS INCLUDES A SPECIFIC PROHIBITION AGAINST FOR-PROFIT
  327.         ORGANIZATIONS DISTRIBUTING THE SOFTWARE, EITHER ALONE OR WITH
  328.         OTHER SOFTWARE, AND CHARGING A "HANDLING" OR "MATERIALS" FEE OR
  329.         ANY OTHER SUCH FEE FOR THE DISTRIBUTION.  NO FOR-PROFIT
  330.         ORGANIZATION IS AUTHORIZED TO INCLUDE THE SOFTWARE ON ANY MEDIA
  331.         FOR WHICH MONEY IS CHARGED.  PERIOD.
  332.  
  333.         No copy of the software may be distributed or given away without
  334.         this document; and this notice must not be removed.
  335.  
  336.         There is no warranty of any kind, and the copyright owner is not
  337.         liable for damages of any kind.  By using this free software,
  338.         you agree to this.
  339.  
  340.         The software and documentation are:
  341.  
  342.                            Copyright (C) 1985-1988 by
  343.                             The Cove Software Group
  344.                              Christopher J. Dunford
  345.                                  P.O. Box 1072
  346.                             Columbia, Maryland 21044
  347.  
  348.                                  (301) 992-9371
  349.                          CompuServe 76703,2002 [IBMNET]
  350.