Skip to content
Justice Tech School

sed Basics

sed edits streams. s/old/new/ replaces, -n with p prints and d deletes lines.

Example
printf "cat\ndog\ncat\n" | sed "s/cat/bird/"
printf "a\nb\nc\n" | sed -n "2p"
printf "a\nb\nc\n" | sed "2d"
echo "aaa" | sed "s/a/b/g"

Result

bird
dog
bird
b
a
c
bbb

Exercise

Replace all on a line.

sed "s/a/b/"

Quiz Test

What does sed 2d do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.