#to unpack this file, just sh thisfilename # these are the sed examples presented in class echo address cat >address <<'END of address' Jean Marshall 3567 quenting Road, Brooklyn, NY John Smith 123 east 67th street, New York, NY Jay Houston 34 west falk road, Houston, Texas SCO 1455 encino road, Santa Clara, Cal Orville Thomas 12345 Oak Bridge Road, Tulsa, OK END of address echo address.script cat >address.script <<'END of address.script' s/NY/New York/ s/OK/Oklahoma/ s/Cal/California/ END of address.script echo address2.script cat >address2.script <<'END of address2.script' s/NY/New York/p s/OK/Oklahoma/p s/Cal/California/p END of address2.script echo animals cat >animals <<'END of animals' I have a cow in the farm and I raise a sheep I also raise a pig We have two types of animals: cows and pigs END of animals echo animals.script cat >animals.script <<'END of animals.script' s/cow/pig/ s/pig/horses/g END of animals.script echo ap2.script cat >ap2.script <<'END of ap2.script' /find/a\ utilty: recursively descends through pathlist and applies expression to\ every file\ see man page for more details. s/recursively/using recursion/ END of ap2.script echo append.script cat >append.script <<'END of append.script' $a\ this goes after the last line in the file\ (matched by $). This text is escaped at the\ end of each line. except for the last one. END of append.script echo bl.script cat >bl.script <<'END of bl.script' /^$/d END of bl.script echo blanklines cat >blanklines <<'END of blanklines' This is a text that contains multiple empty lines sed command contains mutiple functions: substitute function s insert function i delete function d change function c END of blanklines echo braces.script cat >braces.script <<'END of braces.script' /farm/ { s/farm/barn/ s/raise/have/ } END of braces.script echo change.script cat >change.script <<'END of change.script' /find/c\ the find utility recursively descends through pathlist and applies expression\ to every file. END of change.script echo col cat >col <<'END of col' col1 col2 col3 col4 name middle last sex joan d smith f gerry h mill m david m louis m liz f maxman f charles h green m END of col echo col.script cat >col.script <<'END of col.script' s/ /\ /2 END of col.script echo d.script cat >d.script <<'END of d.script' /function/d END of d.script echo d2.script cat >d2.script <<'END of d2.script' /function/!d END of d2.script echo doc cat >doc <<'END of doc' This is a sample document provided for sed examples: .P This is my first paragraph using troff macros .P This is my second paragraph using troff macros This is the list of utilities covered .AL 1 .LI grep .LI find .LI tar .LI cpio .LI sed .LE END of doc echo foo cat >foo <<'END of foo' old program old file old chair in old house we have an old movie and an old vcr in this old house. last line of file foo END of foo echo foo.script cat >foo.script <<'END of foo.script' s/old/new/ END of foo.script echo foo2.script cat >foo2.script <<'END of foo2.script' s/old/new/2 END of foo2.script echo foo3.script cat >foo3.script <<'END of foo3.script' s/old/new/g END of foo3.script echo func cat >func <<'END of func' function(a,b,c) function(a, b, c) END of func echo g.out cat >g.out <<'END of g.out' Consult Section 3.1 in the Owner and Operator Guide for a description of the tape drives available on your system. END of g.out echo gfile cat >gfile <<'END of gfile' Item 1: hand out notices Item 2: collect votes Summary of items END of gfile echo Gscript cat >Gscript <<'END of Gscript' /Item/{ H d } /Summary of items/G END of Gscript echo guide cat >guide <<'END of guide' Consult Section 3.1 in the Owner and Operator Guide for a description of the tape drives available on your system. END of guide echo h.script cat >h.script <<'END of h.script' #edit a line; print the change; replay the original /UNIX/{ h s/.* UNIX \(.*\) .*/\1:/ p x } END of h.script echo hfile cat >hfile <<'END of hfile' This describes the UNIX ls command This describes the UNIX cp command END of hfile echo i.script cat >i.script <<'END of i.script' $i\ this goes before the last line in the file\ (matched by $). This text is escaped at the\ end of each line. except for the last one. END of i.script echo lines cat >lines <<'END of lines' this is a daily list 1. take kids to school 2. exercise for 15 minutes every morning 3. write to Tom 4. prepare lecture 5. cook dinner END of lines echo lines.script cat >lines.script <<'END of lines.script' /^[0-9]/d END of lines.script echo man.script cat >man.script <<'END of man.script' s/_^H//g END of man.script echo N.script cat >N.script <<'END of N.script' /Operator$/{ N s/Owner and Operator\nGuide/Installation Guide/ } END of N.script echo P.script cat >P.script <<'END of P.script' s/function(a,b,c)/function(a,XX,c)/ /function(/{ N s/b/XX/ P D } END of P.script echo tbl cat >tbl <<'END of tbl' sample file containing a table in troff format .sp .TS box; c c c l l l . language authors runs on fortran many almost anything pl\1 IBM 360/370 c BTL 11/45,H6000, 370 .TE .TH "table of languages" END of tbl echo tbl.script cat >tbl.script <<'END of tbl.script' /^\.TS/,/^\.TE/d s/fortran/FORTRAN/ s/table/TABLE/ END of tbl.script echo test1 cat >test1 <<'END of test1' first:second one:two END of test1 echo test1.script cat >test1.script <<'END of test1.script' s/\(.*\):\(.*\)/\2:\1/ END of test1.script echo test2 cat >test2 <<'END of test2' Here is the first sentence: What would you like? Nothing! come on, how about a slice of cake? No, just a drink, please. END of test2 echo test2.script cat >test2.script <<'END of test2.script' s/[\,\.\!\:\?\;]//g END of test2.script echo unix.script cat >unix.script <<'END of unix.script' /UNIX$/{ N /\nSystem/{ s// Operating &/ P D } } END of unix.script echo unix.txt cat >unix.txt <<'END of unix.txt' Here are examples of the UNIX System. Where UNIX System appears, it should be the UNIX Operating System. END of unix.txt