100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

What Is sed?

An introduction to sed, the non-interactive stream editor that transforms text line by line as it flows through a pipeline.

FoundationsBeginner8 min readJul 10, 2026
Analogies

What sed Actually Is

sed is short for 'stream editor'. Unlike a text editor such as vim or nano, sed never opens a file for interactive editing. Instead it reads input one line at a time, applies a set of editing commands you supply in advance, and writes the (possibly transformed) result to standard output. Because it is non-interactive and reads a stream, sed is ideal for automation, scripts, and pipelines where no human is present to press keys.

🏏

Cricket analogy: Like a third umpire who reviews each delivery against fixed rules and signals out or not-out, sed judges every line against commands you set beforehand rather than improvising ball by ball.

The Line-by-Line Model

sed's core loop is simple and worth memorising: read one line into a working buffer called the pattern space, run every command in your script against that buffer, then (by default) print the buffer and move on to the next line. This cycle repeats until the input is exhausted. Understanding that sed sees only one line at a time by default explains why some tasks feel awkward and why sed has a second buffer, the hold space, for carrying data between lines.

🏏

Cricket analogy: Each over is bowled one ball at a time and the scorer records the outcome before the next ball; sed likewise handles one line, prints the result, then faces the next delivery.

A First Look at the Syntax

bash
# Replace the first 'cat' on each line with 'dog', printing the result
echo 'the cat sat on the cat mat' | sed 's/cat/dog/'
# -> the dog sat on the cat mat

# Read from a file and stream the transformed text to stdout
sed 's/ERROR/WARN/' server.log

sed reads from standard input when no filename is given, which is why it slots so naturally into pipelines with a leading pipe (|). Give it one or more filenames and it processes each in turn, concatenating the output.

Where sed Fits Among Its Cousins

sed belongs to the classic Unix text-processing trio alongside grep and awk. grep decides whether a line matches and prints or drops it; sed transforms lines, most famously via substitution; awk is a fuller programming language for field-based records and arithmetic. A good rule of thumb is: reach for grep to filter, sed to do quick find-and-replace or line edits, and awk when you need columns, variables, and computation. They compose beautifully because all three read and write plain text streams.

🏏

Cricket analogy: grep is the selector picking who plays, sed is the physio making a quick adjustment to a player's grip, and awk is the head coach running full tactical analysis with statistics.

sed writes to standard output and does not modify your files by default. To edit a file in place you must pass the -i option, which is easy to forget and irreversible without a backup — always test your script on stdout first.

  • sed is a non-interactive stream editor that transforms text line by line.
  • Its core cycle reads a line into the pattern space, runs your commands, then prints and repeats.
  • By default sed prints to standard output and leaves the original file untouched.
  • With no filename, sed reads stdin, making it a natural fit inside pipelines.
  • sed pairs with grep (filter) and awk (field programming) as the Unix text trio.
  • Substitution (s///) is sed's signature and most-used command.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#SedStreamEditorStudyNotes#WhatIsSed#Sed#Actually#Line#Model#StudyNotes#SkillVeris#ExamPrep