Stream editor for filtering and transforming text.
Synopsis
sed [OPTION]... {script} [FILE]...
Description
A stream editor that performs text transformations on input lines. Supports substitution, deletion, insertion, and more. Runs in the just-bash WASM shell inside SLICC.
Options
-n, --quiet, --silent Suppress automatic printing of pattern space.
-i[SUFFIX], --in-place[=SUFFIX] Edit files in place (optionally creating a backup with SUFFIX).
-e SCRIPT, --expression=SCRIPT Add the commands in SCRIPT to the set.
-E, -r Use extended regular expressions.
Commands
s/REGEXP/REPLACEMENT/FLAGS Substitute matches with replacement. Flags: g (global), i (case-insensitive), n (nth occurrence).
d Delete pattern space.
p Print pattern space.
/PATTERN/COMMAND Apply COMMAND to lines matching PATTERN.
a TEXT Append TEXT after matched line.
i TEXT Insert TEXT before matched line.
c TEXT Replace matched line(s) with TEXT.
y/SOURCE/DEST/ Transliterate characters.
q Quit after current line.
Examples
$ sed 's/foo/bar/g' input.txt
Replace all occurrences of "foo" with "bar".
$ sed -n '5,10p' file.txt
Print lines 5 through 10.
$ sed -i '/^#/d' config.txt
Delete all comment lines in-place.
$ sed 's/old/new/gi' file.txt
Case-insensitive global substitution.
Notes
Operates on the SLICC virtual filesystem (LightningFS/IndexedDB). Supports address ranges (line numbers and patterns). The -i flag writes changes back to the file on the VFS.
See Also
awk, grep, tr, cut