home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / fileutil / change.arj / CHANGE.DOC < prev   
Encoding:
Text File  |  1991-06-01  |  4.8 KB  |  137 lines

  1.  CHANGE
  2.  ======
  3.  String substitution filter
  4.  Copyright (c) 1991 N.G.Hampton
  5.  
  6.  
  7.   Usage:    CHANGE [options] pattern [newstuff] [<infile] [>outfile]
  8.      or        CHANGE [options] /f chgfile [<infile] [>outfile]
  9.  
  10.  
  11.   Options:  /w         Word search
  12.         /i         Ignore case.
  13.         /f         Take substitutions from chgfile
  14.  
  15.  
  16.  Change copies standard input to standard output except that each non-
  17.  overlapping string that matches pattern is replaced by the string newstuff.
  18.  If newstuff is ommitted then the matched string is deleted. Patterns are
  19.  regular expressions as described below; they are matched on a line by line
  20.  basis. Whereever $0 appears in newstuff, the matched pattern is output.
  21.  Parts of pattern may be tagged by placing them between braces ({}); the
  22.  tagged parts may then be referenced by $n in newstuff where n is the nth
  23.  tagged part.
  24.  
  25.  
  26.  When using the /f option, the pattern an substitutions are taken from the
  27.  specified ASCII file. Each substitution should appear on a new line as two
  28.  strings enclosed by double quotes (") and separated by spaces. The first
  29.  string is the string to match, and the second is the substitution.  The
  30.  substitutions are applied in the order in which they appear in the file.
  31.  Each substitution may be prefixed by /w /i or /wi to set the required
  32.  options. Lines starting with a hash (#) character are ignored.
  33.  
  34.  
  35.  Regular Expressions
  36.  ===================
  37.  
  38.  The regular expressions used by this program are similar to those used in
  39.  many UNIX software tools (e.g. grep).
  40.  
  41.  A regular expression is a concatenation of the following elements:
  42.  
  43.         c        literal character c
  44.         .        Any character except newline
  45.         ^        Beginning of line
  46.         $        End of line (null string before newline)
  47.         [...]   Character class (any one of these characters)
  48.         [^...]  Negated character class (all but these characters)
  49.         *        Zero or more occurrences of previous element
  50.         +        One or more occurrences of previous element
  51.         ?        Zero or one occurrence of previous element
  52.         \c        Escaped character (e.g. \[, \*, \\)
  53.  
  54.  Special meaning of characters in a text pattern is lost when escaped.
  55.  A character class consists of zero or more of the following elements,
  56.  surrounded by [ and ]:
  57.  
  58.         c        Literal character, including [
  59.         c1-c2   Range of characters (digits or letters of same case)
  60.         ^        Negated character class if at beginning
  61.         \c        Escaped character (e.g. \^, \-, \\, \])
  62.  
  63.  An escape sequence consists of the character \ followed by a single
  64.  character, or a string of digits, using C language convention.
  65.  
  66.         \n        Newline (carridge return and linefeed)
  67.         \t        Tab
  68.         \xnn    ASCII character nn hex
  69.         \0nnn   ASCII character nnn octal
  70.         \nnn    ASCII character nnn decimal
  71.         \c        c (\\ = \)
  72.  
  73.  
  74.  Regular expression Examples
  75.  ===========================
  76.  
  77.      [A-Za-z]+     Matches with a string containing one or more
  78.              alphabetic characters.
  79.              (e.g. 'A', 'ABxdc', 'AASD')
  80.  
  81.      A[0-9]*     Matches with a string beggining with the letter
  82.              'A' followed by zero or more numeric digits.
  83.              (e.g. 'A32344', 'A', 'A99', 'A0')
  84.  
  85.      ^$         Matches with a blank line.
  86.  
  87.      \[\[         Matches with '[[' only.
  88.  
  89.  
  90.  Change Examples
  91.  ===============
  92.  
  93.  -----------------------------------
  94.  Command  :    CHANGE [A-Za-z]+ XX <CHANGE.DOC
  95.  
  96.  Function :    Changes all words from file CHANGE.DOC into the string
  97.            'XX' and outputs the result to the screen. (CHANGE.DOC
  98.            is not changed).
  99.  
  100.  -----------------------------------
  101.  Command  :    CHANGE "[ \t]+" " " <CHANGE.DOC | CHANGE ^$
  102.  
  103.  Function :    Removes all surplus spaces and then blank lines from
  104.            CHANGE.DOC and outputs the result on the screen.
  105.  
  106.  -----------------------------------
  107.  Command  :    CHANGE "^{[0-9]+} {.*}" "$2 $1" <FRED >JIM
  108.  
  109.  Function :    Takes lines from file FRED beginning with a number and
  110.            followed with any string, and puts the number on the
  111.            end of the line in file JIM.  Non-matching strings are
  112.            output unchanged.
  113.  
  114.  -----------------------------------
  115.  Command  :    ECHO 4+2 = 7 - 1 | CHANGE "[0-9]+[ ]*[+-][ ]*[0-9]+" ($0)
  116.  
  117.  Result      :    (4+2) = (7 - 1)
  118.  
  119.  Function :    To parenthesize all sums and differences of numbers in
  120.            the input.
  121.  
  122.  -----------------------------------
  123.  Command  :    DIR | CHANGE "[0-9]+-[0-9]+-[0-9]+ +[0-9]+:[0-9]+[pa]"
  124.  
  125.  Function :    Removes time and date fields from a directory listing.
  126.  
  127.  -----------------------------------
  128.  Command  :    DIR | CHANGE "^{[A-Z_$]+} +{[A-Z_$]+}{.*}" "$3 $1.$2"
  129.  
  130.  Function :    Places the filename at the end of each directory entry.
  131.  
  132.  -----------------------------------
  133.  Command  :    DIR | CHANGE "^.*<DIR>.*$\n"
  134.  
  135.  Function :    Perform a directory showing names of files only (no
  136.            sub directories.
  137.