The sed
manual describes sed
as a "stream editor" (stream editor). It is capable of filtering text and even has regex support.
As an example, we can create a mock file called example.txt and add text to it.
example.txt
This is one line of text.
Behold, a new line.
Once again, another line of text.
Even more text here.
If we simply try to invoke sed
on this file, we'll get an error:
$ sed example.txt
sed: 1: "example.txt": invalid command code e
You can find and replace in a file using sed
like so:
$ sed 's/line/lawn/' example.txt
This is one lawn of text.
Behold, a new lawn.
Once again, another lawn of text.
Even more text here.
The -i
flag will edit files rather than printing to the screen.