

CH (1)                       4/7/78                        CH (1)


NAME
       ch - make changes in text files

SYNOPSIS
       ch [-ax] [expr ...] fromexpr [toexpr]

DESCRIPTION
       Ch  copies each line of the standard input to the standard
       output, globally substituting the  text  pattern  "toexpr"
       for  "fromexpr"  on  each  line  that  satisfies  matching
       criteria defined by the  leading  expressions  "expr"  and
       the  switches.  (A  text pattern is a subset of a "regular
       expression"--see  the  "ed"   writeup   for   a   complete
       description.)   Three possible courses of action are taken
       depending upon the number of  text  patterns(n)  found  in
       the command line:

       n=1  The  text  pattern is assumed to be "fromexpr" with a
            null "toexpr"; it is equivalent to the ed command
                      g/fromexpr/s///g
       n=2  The first text pattern is "fromexpr", the  second  is
            "toexpr"; it is equivalent to the ed command
                      g/fromexpr/s//toexpr/g
       n>=3 The   (n-1)th  pattern  is  "fromexpr",  the  nth  is
            "toexpr" and patterns 1...n-2 are used  to  determine
            the  lines  upon  which  to perform the substitution.
            The default is that any line which  matches  any  one
            of  the  n-2  leading  expressions  are  eligible for
            substitution.  If the  -a  flag  is  specified,  only
            lines  which match all n-2 leading expressions in any
            order are eligible.  If the  -x  flag  is  specified,
            all  lines which don't satisfy the above criteria are
            eligible.  (See  the  writeup  on   find   for   more
            information.)  In particular, if n=3,
                      ch expr from to
            is equivalent to the ed command
                      g/expr/s/from/to/g
                      ch -x expr from to
            is equivalent to the ed command
                      x/expr/s/from/to/g

       The  substitution  string  "toexpr"  may  be  a  string of
       replacement characters, null to effect a deletion,  or  it
       may  include the special "ditto" character "&" to put back
       the "fromexpr" string and thus effect an insertion.  If  a
       deletion   is   desired  with  the  multiple  leading  tag
       expressions, a "toexpr"  of  ""  -i.e.  quotes  around  an
       empty string may be used. 
       
       A text pattern consists of the following elements:
       
       c         literal character
       ?         any character except newline
       %         beginning of line
       $         end of line (null string before newline)
       [...]     character class (any one of these characters)


                               -1-




CH (1)                       4/7/78                        CH (1)


       [!...]    negated character class (all but these characters)
       *         closure (zero or more occurrences of previous pattern)
       {...}     'tagged' (marked) pattern
       @c        escaped character (e.g., @%, @[, @*)
       
       Any  special  meaning  of  characters in a text pattern is
       lost when escaped, inside [...], or for:
       
       %         not at beginning
       $         not at end
       *         at beginning
       
       A  character  class  consists  of  zero  or  more  of  the
       following elements, surrounded by [ and ]:
       
       c         literal character
       a-b       range of characters (digits, lower or upper case)
       !         negated character class if at beginning
       @c        escaped character (@! @- @ @])
       
       Special  meaning  of  characters  in  a character class is
       lost when escaped or for
       
       !         not at beginning
       -         at beginning or end
       
       An escape sequence consists of the  character  @  followed
       by a single character:
       
       @n        newline
       @t        tab
       @c        c (including @)
       
       For  a  complete  description,  see "Software Tools" pages
       135-154.  Care should be taken when using  the  characters
       %  $  [  ]  { } ! * @ and any shell characters in the text
       pattern. It is  often  necessary  to  enclose  the  entire
       substitution pattern in quotes. 

FILES
       None

SEE ALSO
       sedit, find, tr, ed, the UNIX tool GRES

DIAGNOSTICS
       An  error  message  is  printed  if  the  pattern given is
       illegal. 

AUTHORS
       Original from Kernighan and  Plauger's  "Software  Tools",
       with  modifications  by  Joe  Sventek  (Lawrence  Berkeley
       Laboratory)

BUGS/DEFICIENCIES
       A minus sign(dash[-]) may not start an expression. 


                               -2-


