This page was generated from 34.sed.mth.

This page is part of the course work for CS360: Systems Tools course offered by the Computer Science Department at CalState, San Bernardino, California, USA. It was generated by Dr. Dick Botting.

Contents


    cs360/notes/34.sed

    Why

    You have 200 COBOL programs and to make a Y2K compliant version you need to replace "GETDATE" by "GETDTY2K" where ever it occurs. This is a real example of something a CSUSB student did in the Fall of 1999 -- by hand.

    You want to edit 44 files so that every file name that is used inside them is change to a new one. For example: all the chapter numbers in our book changed and so all the file names changed... and so all the URLs had to change as well. I used the following sed script [ update.sed ] [ update.sed ]

    You need to make the same small substitution in a lot of places in a very large file. Like I need to change "biuld" to "build" in most of my files!

    Tou want to make your HTML web pages from simple ASCII text files.

    .Sections
    (PostIt Note): 34.24
    (why): 34.01 34.16
    (exam): 34.01 34.02 34.04 34.05 34.09 34.10 34.14
    (useful): 34.01 34.02 34.04 34.05 34.06 34.07 34.08 34.09 34.10 34.14 34.19 34.21 34.22 34.23
    (perhaps): 34.11 34.12 34.13 34.15 34.17 34.18 34.20
    (skip): 34.03

    Facts

    Its all in the book!

    I use sed all the day.

    Danger

    Do not use 'sed' like the following:
     		sed commands <myfile >myfile
    because it empties myfile first and then reads the empyt file...

    Use ed to change a file or use a temporary file:

     		sed commands <myfile >tmpfile && mv tmpfile  myfile

    Definitions

  1. sed::command, edit_every_line_input, edit_every_line_in_files.
  2. edit_every_line_input::= sed sed_options sed_commands
  3. edit_every_line_in files::= sed sed_options sed_commands files

  4. files::=one or more files.
  5. sed_options::= empty | -n, Use -n when no printing is assumed.

  6. sed_commands::= -f filename | sed_command, -- ussually need to put it in quotes!

  7. sed_command::= address action.
  8. action::=print | substitute | delete | add | input | quit | ...

  9. address::= See http://www.csci.csusb.edu/dick/cs360/notes/33.ed+ex.html#address.
  10. address::= See http://www.csci.csusb.edu/dick/cs360/notes/33.ed+ex.html#address.
  11. print::= p
  12. substitute::= s/old/new/ substitute_options
  13. substitute_options::= print_option global_option confirm_option.
  14. print_option::=p. global_option=g.
  15. confirm_option::=c.

  16. delete::=d.
  17. add::= s lines.
  18. input::= i lines.
  19. quit::= q.

  20. lines::= sequence of lines terminated by one that has a period and nothing else on it.
  21. symbolic_sed_commands::=following

    See Also

     		man sed

    Questions

    Glossary

  22. TBA::=To Be Announced.

    Submit Your Notes Here

    To earn credit for completing this part of the course you need to send me a short list of things you have learned. A simple way to do this is to follow this [click here [socket symbol] if you can fill this hole] link and fill in the form using copy and paste.

End