This book is new. If you'd like to go through it, then join the Learn Code Forum to get help while you attempt it. I'm also looking for feedback on the difficulty of the projects. If you don't like public forums, then email help@learncodethehardway.org to talk privately.

Exercise 9: sed

Using these tiny projects to study yourself is useful, but let's pan out and look at the main topics you've focused on:

  1. Startup process for beginning work, such as your text editor, how well you can type, and other things that happen inside the computer.
  2. Mental attitude when you begin and while you work, with a suggestion for journaling as a way to get control over it.
  3. Work environment including your desk, lighting, chair, and the kind of computer you use.
  4. Physical posture and health to avoid injuries while you work.

In this exercise we'll take this improvement plan and go one step further by tracking some metrics. You have been taking a small command line tool, reading about it and determining its features, and then spending only 45 minutes doing a quick hack. You can now enumerate your features, prioritize them, and then figure out how many you can complete in 45 minutes. In fact, you can go back through all the projects you've done so far and your notes on changes you've made and calculate this metric to see if you've been improving.

Take the time now to go back through your notes and get a rough estimate of the percentage of features you completed for each 45 minute hack. Graph them on some paper, and then look at your notes to see if there were significant changes, good or bad, when you altered how you work. Then in this exercise try to make a prediction about how much you'll get done based on a change you'll make. You could even try adding some friction back to your process and see how that impacts your productivity.


Keep in mind that this is a personal metric and not something you should share with anyone else. These are barely even scientific and meant for you to simply gain some objectivity in analyzing how you work. They aren't meant to be grand metrics that can describe all programmers, but you better believe that if a manager finds out you have these they will demand to see them. They will then demand everyone on your team start doing them, and then management will use these to cause you a great deal of trouble. Consider your lab notes a very private journal, and never let anyone see it.

Exercise Challenge

This exercise will get more complicated than the others because we're going to be doing more regular expressions and implementing a tool called sed. The sed utility enables you to alter text by taking a regular expression replacement pattern and then determining what to replace it with in each line it receives. The difficulty may be in implementing sed's expression format, so I recommend you approach this in two ways:

  1. Level 1 is having command line options for the most basic sed usage of replacing one string with another.
  2. Level 2 is enabling regular expressions in those command line options.
  3. Level 3 is implementing the sed expression format.

An example of using sed is to change one word to another in a stream of text. If I wanted to change the output of ls so that my name is replaced by "author" I can do this:

ls -l | sed -e "s/zedshaw/author/g"

However, the strength of sed lies in doing regular expressions to match patterns and replace them. If you use the vim editor, then you are already familiar with this syntax:

ls -l | sed -e "s/Jul [0-9][0-9]/DATE/g"

You should read the man sed page, but you may have to do even more research on this to implement it. I suggest you do your research the night before, and then do a 45 minute hack the next day based on that research. This will help you keep your metrics fair and focused on just your work.

Study Drills

  1. Did you find out anything unusual or surprising when you compiled your metrics?
  2. What was your prediction about your work before you started this session?
  3. How did it match what you really did?

Further Study

In the video for this exercise I will show you something called a "run chart". A run chart is a simple graph of some activity you wish to monitor that shows you how it is changing over time. People use run charts to spot big changes in behavior because they are both simple and effective visualization tools. You'll be using run charts more in the book as they are very simple but very powerful.

Pre-order Learn More Python The Hard Way

When you pre-order Learn More Python The Hard Way, you'll receive the Python 3 Edition as it's being created. All files are DRM free and you can download them to your computer for offline viewing. Digital Download Only! You do not get a physical book.


Buy the Online Course

Or, you can read Learn More Python the Hard Way for free right here, video lectures not included.

Other Buying Options

Other buying options coming soon.

No content available for this exercise. You can view all available downloads at your customer account page.