Lecture notes · The Missing Semester · Lecture 4

Data Wrangling

MIT 6.NULL The Missing Semester of Your CS Education, lecture 4, explained in plain English

Want this lecture to stick? In LessonBound you get checked practice questions for every part, can ask about anything you don't get, and can listen with your screen off. Free, no ads.

Learn this lecture free

Watch or read the original lecture: MIT OpenCourseWare.

Part 1

This part teaches how to reshape messy log text into a short, useful list, using pipes, the sed tool, regular expressions, and sort with uniq.

Key ideas

Words to know

regular expression
A pattern written with plain letters and special symbols that describes the text you want to find, such as 'any characters followed by the word Disconnected from'.
pipe (|)
A symbol that passes the output of one command straight into the next command, like a conveyor belt between steps.
greedy
When a pattern grabs as much text as it possibly can, which can make it match more than you intended.
capture group
A part of a pattern wrapped in parentheses so that the text it matched can be saved and reused, for example as \2.

Example

Think of sorting a pile of mail to find who sent the most letters. First you pull out only the letters from one sender, then you cut off the return address and keep just the name, and finally you line up the names so the same ones sit together and count them. Each step is a small tool passing its result to the next one.

3 checked practice questions for this part are in the app.

Part 2

This part shows how to count, sort, and reshape lines of text in the shell, and how to use awk and bc to do more with that text.

Key ideas

Words to know

field
One chunk of a line, separated from the next chunk by a divider. By default, awk treats spaces and tabs as dividers, so each word in a line is a field.
delimiter
The character that separates one piece of text from the next, such as a comma or a space.
awk
A small programming language built for processing text line by line. The lesson uses it to pick out fields and do simple counting.
regular expression
A short written pattern that describes a set of text, such as words that start with c and end with e. The lesson uses one inside an awk pattern.

Example

Imagine a stack of paper ballots where people wrote their favorite fruit. You could group the same fruit together, count each group, and then list the most popular ones first. The shell tools in this lesson do the same kind of job on lines of text.

3 checked practice questions for this part are in the app.

← Lecture 3: Editors (Vim) · Lecture 5: Command-line Environment →

Notes written by AI (Claude) from the lecture's official transcript, so check anything important against the lecture. MIT CSAIL · CC BY-NC-SA 4.0 · not affiliated with or endorsed by MIT. These notes are shared under the same license.

LessonBound · Free lecture notes · Privacy · Terms · New York