Find-and-Replace with Sed

Ayelet Drazen

2023-01-18

Using sed

sed is one of the most powerful commands when it comes to data wrangling in the shell. It’s called a “stream editor” because you can use it to make edits to a “stream” of text, which could either be a file or the output of another program.

Find-and-Replace

The simplest way to use sed is for finding a word and replacing it with another word:

cat input.txt | sed 's/hello/hi/g'

Let’s look at this in detail:

Regular Expressions

xkcd 1171

We can also use sed with regular expressions, just like we did with grep in our previous post.