0Pricing
Linux Command Line Mastery · Lesson

Stream Editing at Scale with sed and tr

Apply regex-powered transformations across streams using sed substitution and translate or delete characters with tr.

Stream Editing at Scale with sed and tr is a free Linux Command Line Mastery lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

From Matching to Transforming

You have mastered regex matching with grep and find. The natural next step is transforming the text you match. sed and tr turn your regex skills into edits.

sed Substitution Basics

The s/pattern/replacement/ command replaces the first match per line. Add g for all matches.

echo 'cat cat cat' | sed 's/cat/dog/g'

Using Regex in sed

sed -E enables extended regex so you can use +, ?, and groups without backslashes.

echo 'a123b' | sed -E 's/[0-9]+/#/'

Capture Groups and Backreferences

Parentheses capture parts of the match; \1, \2 reuse them in the replacement. Here we swap two words.

echo 'John Smith' | sed -E 's/(\w+) (\w+)/\2 \1/'

Anchoring Substitutions

Use ^ and $ to act only at the start or end of a line, e.g. prefixing every line.

printf 'one\ntwo\n' | sed 's/^/> /'

Deleting and Selecting Lines

sed can target lines by pattern: /regex/d deletes matching lines, while -n '/regex/p' prints only matches.

printf 'keep\ndrop me\nkeep\n' | sed '/drop/d'

In-Place Editing

sed -i edits a file directly. Always keep a backup with -i.bak until you trust the command.

sed -i.bak 's/localhost/127.0.0.1/g' config.conf

Meet tr

tr translates or deletes characters (not regex). It reads stdin only. Here we uppercase text.

echo 'hello' | tr 'a-z' 'A-Z'

Deleting and Squeezing

tr -d removes characters and tr -s squeezes repeats into one, great for cleaning whitespace.

echo 'a   b    c' | tr -s ' '

Combining sed and tr

Chain them: normalize a CSV by converting commas to newlines and stripping carriage returns.

echo 'a,b,c' | tr ',' '\n' | sed 's/^/item: /'

When to Use Which

Reach for sed when you need patterns and line logic; reach for tr for fast single-character translations and deletions.

Quick Check

You want to replace every occurrence of a word on each line with sed. What must you add?

Recap

You can now transform streams with regex:

  • sed 's///g' substitutes; -E enables extended regex; \1 reuses captures
  • /re/d and -n '/re/p' select lines
  • sed -i.bak edits files safely
  • tr translates, deletes (-d), and squeezes (-s) characters

Frequently asked questions

Is the “Stream Editing at Scale with sed and tr” lesson free?

Yes — the full text of “Stream Editing at Scale with sed and tr” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Stream Editing at Scale with sed and tr”?

Apply regex-powered transformations across streams using sed substitution and translate or delete characters with tr. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Command Line Mastery?

No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Stream Editing at Scale with sed and tr” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Command Line Mastery lesson?

Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Mastering Regular Expressions (Regex)
  2. Advanced `grep` and `find` Patterns
  3. `xargs` for Command Chaining
  4. Stream Editing at Scale with sed and tr
← Back to Linux Command Line Mastery