home *** CD-ROM | disk | FTP | other *** search
- CHANGE
- ======
- String substitution filter
- Copyright (c) 1991 N.G.Hampton
-
-
- Usage: CHANGE [options] pattern [newstuff] [<infile] [>outfile]
- or CHANGE [options] /f chgfile [<infile] [>outfile]
-
-
- Options: /w Word search
- /i Ignore case.
- /f Take substitutions from chgfile
-
-
- Change copies standard input to standard output except that each non-
- overlapping string that matches pattern is replaced by the string newstuff.
- If newstuff is ommitted then the matched string is deleted. Patterns are
- regular expressions as described below; they are matched on a line by line
- basis. Whereever $0 appears in newstuff, the matched pattern is output.
- Parts of pattern may be tagged by placing them between braces ({}); the
- tagged parts may then be referenced by $n in newstuff where n is the nth
- tagged part.
-
-
- When using the /f option, the pattern an substitutions are taken from the
- specified ASCII file. Each substitution should appear on a new line as two
- strings enclosed by double quotes (") and separated by spaces. The first
- string is the string to match, and the second is the substitution. The
- substitutions are applied in the order in which they appear in the file.
- Each substitution may be prefixed by /w /i or /wi to set the required
- options. Lines starting with a hash (#) character are ignored.
-
-
- Regular Expressions
- ===================
-
- The regular expressions used by this program are similar to those used in
- many UNIX software tools (e.g. grep).
-
- A regular expression is a concatenation of the following elements:
-
- c literal character c
- . Any character except newline
- ^ Beginning of line
- $ End of line (null string before newline)
- [...] Character class (any one of these characters)
- [^...] Negated character class (all but these characters)
- * Zero or more occurrences of previous element
- + One or more occurrences of previous element
- ? Zero or one occurrence of previous element
- \c Escaped character (e.g. \[, \*, \\)
-
- Special meaning of characters in a text pattern is lost when escaped.
- A character class consists of zero or more of the following elements,
- surrounded by [ and ]:
-
- c Literal character, including [
- c1-c2 Range of characters (digits or letters of same case)
- ^ Negated character class if at beginning
- \c Escaped character (e.g. \^, \-, \\, \])
-
- An escape sequence consists of the character \ followed by a single
- character, or a string of digits, using C language convention.
-
- \n Newline (carridge return and linefeed)
- \t Tab
- \xnn ASCII character nn hex
- \0nnn ASCII character nnn octal
- \nnn ASCII character nnn decimal
- \c c (\\ = \)
-
-
- Regular expression Examples
- ===========================
-
- [A-Za-z]+ Matches with a string containing one or more
- alphabetic characters.
- (e.g. 'A', 'ABxdc', 'AASD')
-
- A[0-9]* Matches with a string beggining with the letter
- 'A' followed by zero or more numeric digits.
- (e.g. 'A32344', 'A', 'A99', 'A0')
-
- ^$ Matches with a blank line.
-
- \[\[ Matches with '[[' only.
-
-
- Change Examples
- ===============
-
- -----------------------------------
- Command : CHANGE [A-Za-z]+ XX <CHANGE.DOC
-
- Function : Changes all words from file CHANGE.DOC into the string
- 'XX' and outputs the result to the screen. (CHANGE.DOC
- is not changed).
-
- -----------------------------------
- Command : CHANGE "[ \t]+" " " <CHANGE.DOC | CHANGE ^$
-
- Function : Removes all surplus spaces and then blank lines from
- CHANGE.DOC and outputs the result on the screen.
-
- -----------------------------------
- Command : CHANGE "^{[0-9]+} {.*}" "$2 $1" <FRED >JIM
-
- Function : Takes lines from file FRED beginning with a number and
- followed with any string, and puts the number on the
- end of the line in file JIM. Non-matching strings are
- output unchanged.
-
- -----------------------------------
- Command : ECHO 4+2 = 7 - 1 | CHANGE "[0-9]+[ ]*[+-][ ]*[0-9]+" ($0)
-
- Result : (4+2) = (7 - 1)
-
- Function : To parenthesize all sums and differences of numbers in
- the input.
-
- -----------------------------------
- Command : DIR | CHANGE "[0-9]+-[0-9]+-[0-9]+ +[0-9]+:[0-9]+[pa]"
-
- Function : Removes time and date fields from a directory listing.
-
- -----------------------------------
- Command : DIR | CHANGE "^{[A-Z_$]+} +{[A-Z_$]+}{.*}" "$3 $1.$2"
-
- Function : Places the filename at the end of each directory entry.
-
- -----------------------------------
- Command : DIR | CHANGE "^.*<DIR>.*$\n"
-
- Function : Perform a directory showing names of files only (no
- sub directories.
-