Solutions to HW 4 ------------------ 1. Here's a verbose sed script, more elaborate than it needs to be. Put it in reverse.f and invoke as: sed -n -f reverse.f : 1{ h b } ${ p g p b } { x H } 2. Once again here is a rather complicated looking script. It is written so elaborately only to illustrate aspects of sed such as branching. You will still get credits if you wrote a simple pattern expression such as: /[Pp][Rr][Ee][Ss][Ii][Dd][Ee][Nn][Tt]/. Invoke the script with the "-n" option. { h # save the line in the hold buffer y/president/PRESIDENT/ s/PRESIDENT/anythinggoeshere/ t777 # see if a substitution happened, and jump to 777 if so: b :777 g # bring back the line from the hold buffer p } 3. Here's an sed script. We first search for the desired phrase in a single line. If we find it, we do the replacement. Else, we read in another line, get rid the embedded newline, and then perform the desired replacement. Invoke it without the "-n" option. s/Virginia Polytechnic Institute and State University/Virginia Tech/ /Polytechnic/ { N s/ *\n/ / s/Virginia Polytechnic Institute and State University\([\.,]\) /Virginia Tech\1\ / }