Stage 3 · Lesson 6 of 8
Editing streams with sed
is a stream editor: it changes text as it flows past, line by line. Its most common use is find and replace. sed 's/old/new/g' file prints the file with every "old" replaced by "new".
The g at the end means every match on a line, not just the first. -n together with p prints only the lines you pick. -i edits the file in place instead of printing it. sed is ideal for quick edits you repeat in scripts, such as changing a version number in a . On , sed -i needs an extra empty (-i '') because it is the version.
Common traprunning sed -i on files without a backup or Git, then discovering the pattern matched more than you expected.
A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CourseFreeThe Missing Semester of Your CS Education
MIT · Beginner
The data wrangling lecture walks through grep, sed, awk and regular expressions on real logs
- BookFreeThe Linux Command Line
William Shotts · Beginner
Clear chapters on text processing, regular expressions and searching for files