Linux, terminal and Git

Stage 3 · Lesson 6 of 8

Editing streams with sed

Text tools

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

Practise

  • Test regular expressions on sample text with a plain explanation of each part

  • Middle levels need grep, sort, uniq and find to locate the next password

Keep handy

  • The official jq manual with examples for every filter

  • Quick examples for find, sed, awk and friends when you forget the syntax

Mark this stage as not done?