Sed Exercises

Questions and Answers

How do you run a substitute command with sed?

Click Here for Answer
sed 's/word-or-phrase-to-replace/replacement-word-or-phrase/' file-name

How do you use the substitute command to add additional text?

Click Here for Answer
sed 's/word-or-phrase/& additional-text-to-add/' file-name

Working with the user.csv Dataset

Using the user.csv Dataset complete the following requirements:

Note

If you need to get the user.csv Dataset again you can do so with the following command:

curl -s https://launchcodelearning.org/api/walkthrough/user?data_format=csv > user.csv

Substitute all employers by the name of Hunter Engineering for LaunchCode

Click Here for Solution
sed 's/Hunter Engineering/LaunchCode/' user.csv

Add the additional text “: Kansas City” to all users employed at VMLY&R

Click Here for Solution
sed 's/VMLY&R/&: Kansas City/' user.csv

Substitute all email signatures (@example.org, @example.net, @example.com) for @launchcode.org

Click Here for Solution
sed 's/\(@example.org\|@example.net\|@example.com\)/@launchcode.org/' user.csv > launchcode-emails.csv

or

sed 's/@example.org/@launchcode.org/' user.csv | sed 's/@example.net/@launchcode.org/' | sed 's/@example.com/@launchcode.org/' > all-launchcode-emails.csv