How To Install Sed On Debian, Ubuntu, Alpine, Arch, Kali, CentOS, Fedora And Raspbian?

How To Install Sed On Debian, Ubuntu, Alpine, Arch, Kali, CentOS, Fedora And Raspbian?

sed

Edit text in a scriptable manner.

Maintainer: Clint Adams



Section: utils

Install sed

  • Debian apt-get install sed Click to copy
  • Ubuntu apt-get install sed Click to copy
  • Alpine OS apk add sed Click to copy
  • Arch Linux pacman -S sed Click to copy
  • Kali Linux apt-get install sed Click to copy
  • CentOS yum install sed Click to copy
  • Fedora dnf install sed Click to copy
  • Raspbian apt-get install sed Click to copy

Edit text in a scriptable manner.

How to use sed?

Below are few example commands for sed that you can use in the terminal.

Replace the first occurrence of a regular expression in each line of a file, and print the result:
sed 's/regex/replace/' filenameClick to copy
Replace all occurrences of an extended regular expression in a file, and print the result:
sed -r 's/regex/replace/g' filenameClick to copy
Replace all occurrences of a string in a file, overwriting the file (i.e. in-place):
sed -i 's/find/replace/g' filenameClick to copy
Replace only on lines matching the line pattern:
sed '/line_pattern/s/find/replace/' filenameClick to copy
Delete lines matching the line pattern:
sed '/line_pattern/d' filenameClick to copy
Print only text between n-th line till the next empty line:
sed -n 'line_number,/^$/p' filenameClick to copy
Apply multiple find-replace expressions to a file:
sed -e 's/find/replace/' -e 's/find/replace/' filenameClick to copy
Replace separator / by any other character not used in the find or replace patterns, e.g., #:
sed 's#find#replace#' filenameClick to copy
Installing sed command is simple. just copy one of the above commands for your operating system and paste it into terminal. This command is available for Debian, Ubuntu, Alpine, Arch, Kali, CentOS, Fedora and Raspbian operating systems. Once you run the command it will install the latest version of sed 2026 package in your OS.