home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / irix / scripts / replace < prev    next >
Encoding:
Text File  |  1994-08-02  |  1.1 KB  |  46 lines

  1. #! /bin/csh -f
  2. #
  3. # $Id: replace,v 1.1 93/11/19 13:53:11 carlson Exp $
  4. #
  5. # This script will search a number of files for a string
  6. # and replace the string.  Sort of a global find-and-replace.
  7. #
  8. # Format of call:
  9. #    replace <search-string> <replace-string> <file-list>
  10. #
  11. #    Where:
  12. #    <search-string>        Is a regular expression (as used in ed)
  13. #                that is supposed to be found in the list
  14. #                of files.
  15. #    <replace-string>    Is the string that is to replace the
  16. #                <search-string>.
  17. #    <file-list>        List of files to perform the find-and-
  18. #                replace on.
  19. #
  20. # Revision History:
  21. #    $Log:    replace,v $
  22. # Revision 1.1  93/11/19  13:53:11  carlson
  23. # Initial revision
  24. # 6 Jun 1989  Christopher W. Carlson, Silicon Graphics Inc.
  25. # Initial draft.
  26. #
  27. #---------------------------------------------------------------------------
  28. if ( argc < 4) then
  29.     echo "Usage: replace <search-string> <replace-string> <file-list>"
  30.     exit
  31. endif
  32.  
  33. set noglob
  34. set search = $1
  35. shift
  36. set replace = $1
  37. shift
  38. unset noglob
  39.  
  40. foreach file ( $* )
  41.     echo "Doing $file:"
  42.     sed -e "s/$search/$replace/gp" < $file > tmp$$
  43.     if ( $status == 0 ) mv tmp$$ $file
  44. end
  45.