Intermediate Package: sed

sed

Stream editor for filtering and transforming text.

Syntax

sed [options] script [file...]

Description

sed applies editing commands (most commonly find-and-replace) to a stream of text line by line, making it the standard tool for scripted, non-interactive text transformation.

Examples

sed "s/foo/bar/" file.txt
Replace the first occurrence of "foo" with "bar" on each line
sed -i "s/foo/bar/g" file.txt
Replace every occurrence in-place, editing the file directly
sed -n "5,10p" file.txt
Print only lines 5 through 10

Applies to

Ubuntu Debian Linux Mint RHEL CentOS / Rocky / AlmaLinux Fedora Arch Linux openSUSE Alpine Linux