Stream editor for parsing and transforming text using pattern matching and substitution operations.
sed {quiet} {expression} {file} {follow-symlinks} {in-place} ๐ quiet ๐ expression ๐ file ๐ follow-symlinks ๐ in-place sed {quiet} {expression} {file} {follow-symlinks} {in-place} Sandbox: execFile · Timeout: 30s
text.transform.substitute text.transform.delete text.transform.insert text.transform.append text.filter.line text.process.stream | Name | Type | Required | Default | Description | Aliases |
|---|---|---|---|---|---|
quiet | string | No | - | suppress automatic printing of pattern space --debug annotate program execution | -n, --quiet, --silent |
expression | string | No | - | add the script to the commands to be executed | -e, --expression |
file | file | No | - | add the contents of script-file to the commands to be executed | -f, -f, -f, --file |
follow-symlinks | string | No | - | follow symlinks when processing in place | --follow-symlinks |
in-place | string | No | - | edit files in place (makes backup if SUFFIX supplied) | -i, --in-place |
line-length | integer | No | - | specify the desired line-wrap length for the `l' command | -l, --line-length |
posix | string | No | - | disable all GNU extensions | --posix |
regexp-extended | string | No | - | use extended regular expressions in the script (for portability use POSIX -E) | -E, -r, --regexp-extended |
separate | string | No | - | consider files as separate rather than as a single, continuous long stream. --sandbox operate in sandbox mode (disable e/r/w commands) | -s, --separate |
unbuffered | file | No | - | load minimal amounts of data from the input files and flush the output buffers more often | -u, --unbuffered |
null-data | string | No | - | separate lines by NUL characters --help display this help and exit --version output version information and exit | -z, --null-data |
help | boolean | No | - | display this help and exit | --help |
sandbox | boolean | No | - | --sandbox | |
version | boolean | No | - | output version information and exit | --version |
| Type | Description | MIME | Schema | Trust |
|---|---|---|---|---|
text.transformed | Text after sed transformation | text/plain | - | verified |
Inputs
text.plain Input text stream to transform
Outputs
text.transformed Text after applying sed script
Produces
text.transformedConsumes
text.plain| Resource | Value |
|---|---|
| CPU | low |
| Memory | 8 MB |
| Network | none |
| Disk I/O | low |
Find and replace first occurrence per line
sed 's/old/new/' file.txt Global find and replace all occurrences
sed 's/old/new/g' file.txt In-place edit with backup
sed -i.bak 's/foo/bar/g' config.txt Delete lines matching a pattern
sed '/^#/d' config.conf Print lines 10-20
sed -n '10,20p' file.txt Delete trailing whitespace
sed 's/[[:space:]]*$//' file.txt Darkiros UTILS: Replace multiple space to one
sed -e 's/ */ /g' Darkiros UTILS: Remove the last char
sed 's/.$//' Preview a file edit, via substitution.
sudo sed 's/Name=Xfce Session/Name=Xfce_Session/' FILE Replace the same string more than once per line (g flag)
sudo sed 's/Name=Xfce Session/Name=Xfce_Session/g' FILE Edit a file (adding -i flag), in-place; changes are made to the file(s).
sudo sed -i 's/Name=Xfce Session/Name=Xfce_Session/' FILE It can become necessary to escape special characters in your string.
sed -i 's/\/path\/to\/somewhere\//\/path\/to\/anotherplace\//' FILE Change your sed delimiter to a pipe to avoid escaping slashes.
sed -i 's|/path/to/somewhere/|/path/to/anotherplace/|' FILE Print 2nd line
sed -n '2p' FILE Print lines from 2 till 9
sed -n '2,9p' FILE Print lines starting from one having pattern "any" till line number 17
sed -n '/any/,17p' FILE Print lines starting from the beginning, quit after printing 3rd line
sed -n 'p;3q' Print and quit at 5th line
sed -n '5{p;q}' FILE Print lines starting from the one having pattern "strstart" till the line having pattern "strend"
sed -n '/strstart/,/strend/p' FILE Print the last line
sed -n '$p' FILE Replace tabs with 4 spaces (changes are written to file itself)
sed -i 's/\t/ย ย ย /g' FILE Replace CRLF with LF (convert DOS/Windows line endings to Linux line endings)
sed -i 's/\r$//g' FILE Insert CR (carriage return) character before LF (line feed) character (Linux to DOS/Windows line endings conversion)
sed -i 's/$/\r/' FILE Remove trailing spaces (changes are written to file itself)
sed -i -E "s/\s+$//g" FILE Remove empty lines (changes are written to file itself)
sed -i -E "/^\s*$/d" FILE Anonymize original MAC address of an Ethernet device in ifconfig's output (match 6 pairs of hexadecimal numbers with an optional trailing ":")
ifconfig | sed -E "/ether/ s/([0-9a-f]{2}:{0,1}){6}/00:00:00:00:00:00/g" Rearrange order of %Y,%m,%d in `date`s output by matching groups of characters
date '+%Y-%m-%d' | sed -E "s/([0-9]{4})-([0-9]{2})-([0-9]{2})/\3-\2-\1/" Sed is a non-interactive stream editor that performs text transformations on input streams. It's ideal for automated text processing in scripts and pipelines, particularly find-and-replace operations.
# Basic substitution (first match per line)
sed 's/pattern/replacement/' file.txt
# Global substitution (all matches)
sed 's/pattern/replacement/g' file.txt
# Case-insensitive
sed 's/pattern/replacement/gi' file.txt
# Replace only on specific lines
sed '3s/pattern/replacement/' file.txt
sed '10,20s/pattern/replacement/g' file.txt
# Delete lines
sed '5d' file.txt # Delete line 5
sed '/^$/d' file.txt # Delete empty lines
sed '/^#/d' file.txt # Delete comments
# Print specific lines
sed -n '5p' file.txt # Print line 5 only
sed -n '/error/p' file.txt # Print lines containing 'error'
# Insert and append
sed '2i\inserted line' file.txt # Insert before line 2
sed '2a\appended line' file.txt # Append after line 2
# Edit file directly (BSD/macOS requires space)
sed -i '' 's/foo/bar/g' file.txt # macOS
sed -i 's/foo/bar/g' file.txt # Linux
# Create backup
sed -i.bak 's/foo/bar/g' file.txt
# Chain with -e
sed -e 's/foo/bar/' -e '/^$/d' file.txt
# Chain with semicolons
sed 's/foo/bar/; /^$/d' file.txt
# From a script file
sed -f script.sed file.txt