SED Homework
Copy this page to a word document, and fill in all the underlines. Most will be filled with a copy of the commands you enter on your linux system.
Use this file to test your commands. (Right click on the file to save it to your desktop, and then open the file and copy. Then sign onto panther and type vi sedfile and then i and then paste and then escape ZZ. )
First, do questions 3.2- 4.3 on this SED Worksheet. You do not have to turn in anything but it will prepare you to do the worksheet below.
Some nice tutorials you may want to refer to: (and again nothing to turn in.)
1. Use sed to change a text so that every period at the end of a sentence is changed to an exclamation point (!) and every question mark is replaced with an ellipsis (...). (Note: Copy the command you entered on your linux system to answer all these questions.)
_____________________________________________________________________________________________________
2. Change every occurrence of the word 'me' with 'you' but only at the end of a line.
_____________________________________________________________________________________________________
3. Use sed to change a document so that every occurrence of a three-letter abbreviation for a month is replaced by the appropriate number, i.e., Jan isr replace by 1, Feb by 2 etc.
_____________________________________________________________________________________________________
4. Pull only the dates in the format YYYY-MM-DD out of a document. (Print only the first occurence of this pattern on a line.
Some reminders:
_____________________________________________________________________________________________________
5. Pull out all the email addresses from a document. (Email has a pattern of xxxx@xxx.x. You only need to pull one per line. See the comments from #4.)
_____________________________________________________________________________________________________
6. Optional (You can skip if you find it too difficult) - Question 1 of http://inst.eecs.berkeley.edu/~selfpace/studyguide/cs9e/practice_quiz/03-grepsed/
_____________________________________________________________________________________________________
7. Optional (You can skip if you find it too difficult) - Question 2 of http://inst.eecs.berkeley.edu/~selfpace/studyguide/cs9e/practice_quiz/03-grepsed/
_____________________________________________________________________________________________________
8. I want to you to look at the scripting before we go over it in class on Friday. Can you please use VI firstvarscript to type in the program found on page 28 in your book. I did hand out that page in class. Change the script to become executable using chmod +x firstvarscript. Run it and examine the contents. Copy the 4 echo lines and paste them into your program and change those copied 4 lines to use $0 instead of $myvar. Copy those 4 echo lines and past them into your program and then change those 4 copied lines to use date instead of $myvar. Add one more line to echo `date`, using the angled quote above the tab key and next to the 1 key on your keyboard. Run your new program. Tell me what the $0 is holding (what does it print) and what being inside double quotes does to an echoed string: (Note, you just have to answer this question, not give me the script.) :
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________