sed is a stream editor commonly used on Unix/Linux and macOS systems to process and transform text. It reads input line by line, applies commands, and outputs the modified text.
Some common uses include:
-
Replace text
Replaces the first occurrence of apple with orange on each line.
-
Replace all occurrences
The g flag means "global" (replace every occurrence on each line).
-
Delete lines
Deletes line 3.
-
Print specific lines
Prints only line 5.
-
Edit a file in place
Modifies file.txt directly.
sed is especially useful in shell scripts and command pipelines, for example:
It is fast, lightweight, and ideal for automating repetitive text editing tasks.
If you're learning Linux, sed is one of the most valuable command-line tools alongside grep, awk, and cut.