hw12: Reading about sed back-references
- Due before the beginning of class on Monday, February 6
Today’s homework asks you to do some reading about sed
and then fill
in and submit a
markdown file
to check your understanding.
Reading
Required:
Read Chapter 20 of TLCL, just the section on “Editing on the fly”.
This goes through the tr
command a little bit, and then goes into
great detail on the sed
command. We have been using sed
already, but
the reading here goes into some of the more powerful things which we
haven’t learned about yet.
Stop reading when you get to the stuff about aspell
.
Optional: [ABSG section on sed][https://tldp.org/LDP/abs/html/x23170.html].
This doesn’t go into as much detail as the required reading above, but
can be a good quick reference and links to a large variety of examples
using sed
within broader bash contexts.
Questions
Did you read the required reading, “Editing on the fly” from TLCL chapter 20?
(Answer “yes” if you did.)
Which of these commands would remove empty items from a comma-separated list, like turning “
blue,green,,,orange,,yellow
” into “blue,green,orange,yellow
”?tr ',,' ','
tr -d ',,'
tr -s ','
tr -e ',,' ','
(Enter just the letter of the correct choice.)
What does the following command do?
sed 's/\([0-9]\{2\}\)\/\([0-9]\{2\}\)\/\([0-9]\{4\}\)$/\3-\1-\2/'
- Changes dates like
02/01/2023
to2023-02-01
- Changes phone numbers like `(302) 555.0417
to
302-555-0417` - Performs long division by doing repeated subtractions
- This question is impossible for mortal humans to answer
- Changes dates like
Which of these commands would shorten long proper nouns to their first three letters, like
Delaware
would becomeDel.
andMidshipman
would becomeMid.
?sed -E '/\b[A-Z]\w\w(\w*)/d'
sed -E 's/\b[A-Z]\w\w(\w*)/\1/./'
sed -E 'y/[A-Z]\w\w\w*/[A-Z]\w\w./'
sed -E 's/\b([A-Z]\w\w)\w*/\1./'
Submit command
To submit files for this homework, run one of these commands:
submit -c=sd212 -p=hw12 hw12.md
club -csd212 -phw12 hw12.md
Download the file hw12.md to fill in and submit for this homework