PDF Version Available
This document is also available in PDF format: sedlab.pdf
The PDF version includes bookmarks for easy navigation and is optimized for printing.
Accessibility Notice
This document is also available in HTML format at:
https://aholdengouveia.name/LinuxAdmin/labexcercises/sedlab.html
The HTML version provides enhanced accessibility features including keyboard navigation, screen reader support, responsive design, dark mode support, and high contrast options.
Objectives:
- The objective of this lab is to introduce students to sed, the stream editor that enables powerful text transformation and automated file editing in Linux environments. Through hands-on exercises, students will learn to perform substitutions, deletions, insertions, and conditional operations on text files using sed's pattern matching and regular expressions, develop sed scripts for complex multi-step transformations, and master techniques essential for automated configuration management, log processing, and bulk text modifications in system administration.
Complete the following problems
References, a video and some notes are available at my website
Please include the command, a screenshot showing it works as intended, cite all sources you used, and give a short explanation of how the command works and why.
- Change the name Jo to Josephine
- Delete the last 5 lines.
- Print lines 3-15.
- Delete lines for people who live in California
- Print all lines where the birthdays are in the first week of the month. Be careful of the dates for birthdays, the format is MM/DD/YY
- Append three asterisks (*) to the end of lines starting with Sir
- Replace the line containing "Westley Pirate" with the phrase "As you wish." Make sure you replace the whole line not just the name
- Change Minerva McGonagall's birthday to 10/04/1935. Assume you don't know Minerva's original birthday. Use a regular expression to search for it.
- Delete all blank lines.
- Write a sed script that will (actual sed script, NOT just the commands on the command line) enumerate
- Insert above the first line the title - Great Literary Characters -.
- Print the contents of the file, but instead of the phone number starting with an area code, have it start with a 1+, then include the area code and number. For example, (603)123-1234 would turn into 1+(603)123-1234
- Append at the end of the file "Happily Ever after. The End"
Deliverables
A text document with the grep statements used to get each result. Clearly labeled so I can see which answer goes to which question.
Please include the command, a screenshot that includes the command and a few results showing it works as intended, cite all sources you used, and give a short explanation of how the command works and why. Make sure everything is in your own words. Think of the explanation as you trying to walk someone through how to use sed when they haven't heard of it before.