SED(1)

๐ŸŽ€ SED(1) ๐ŸŽ€ โ€” she's a stream editor and she's THAT girl

okay bestie, sit down, hydrate, because today we're talking about sed ๐Ÿ’… this is the manual page for the GNU stream editor for filtering and transforming text, and yes she's a User Command, yes she's iconic, no you cannot skip her.


โœจ SYNOPSIS โœจ

like, the whole vibe in one code block:

sed [-V] [--version] [--help] [-n] [--quiet] [--silent]
    [-l N] [--line-length=N] [-u] [--unbuffered]
    [-E] [-r] [--regexp-extended]
    [-e script] [--expression=script]
    [-f script-file] [--file=script-file]
    [script-if-no-other-script]
    [file...]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

So. sed is a stream editor. And a stream editor is a little program that does basic text transformations on an input stream โ€” and by "input stream" I mean either a file or input coming at you through a pipeline. ๐Ÿซถ

Now, she is kinda similar to editors that let you script your edits (looking at you, ed), but here's the difference that makes her the main character: sed makes only one pass over the input(s), which makes her way more efficient. But honestly? The thing that really sets her apart from every other editor type is her ability to filter text in a pipeline. it's giving legend behaviour, no cap. ๐Ÿ‘‘

Here's the option menu, bestie, every single one, don't scroll past:

  • -n, --quiet, --silent โ€” suppresses the automatic printing of the pattern space. she goes quiet, but she's still working.
  • --debug โ€” annotates the program execution, like little commentary notes while she runs.
  • -e script, --expression=script โ€” adds the script to the commands that get executed.
  • -f script-file, --file=script-file โ€” adds the contents of script-file to the commands that get executed.
  • --follow-symlinks โ€” follows symlinks when processing in place.
  • -i[SUFFIX], --in-place[=SUFFIX] โ€” edits files in place (and it makes a backup if SUFFIX is supplied).
  • -l N, --line-length=N โ€” specifies the desired line-wrap length for the l command.
  • --posix โ€” disables all GNU extensions. bye extensions ๐Ÿ’€
  • -E, -r, --regexp-extended โ€” uses extended regular expressions in the script (for portability, use POSIX -E).
  • -s, --separate โ€” considers files as separate instead of as a single, continuous long stream.
  • --sandbox โ€” operates in sandbox mode (disables the e/r/w commands).
  • -u, --unbuffered โ€” loads minimal amounts of data from the input files and flushes the output buffers more often.
  • -z, --null-data โ€” separates lines by NUL characters.
  • --help โ€” displays this help and exits.
  • --version โ€” outputs version information and exits.

Now, important logistics ๐Ÿ“‹: if no -e, --expression, -f, or --file option is given, then the first non-option argument gets taken as the sed script to interpret. All the remaining arguments are names of input files, and if you don't specify any input files at all, then standard input gets read. periodt.

GNU sed home page: <https://www.gnu.org/software/sed/>. General help using GNU software: <https://www.gnu.org/gethelp/>. E-mail bug reports to: <bug-sed@gnu.org>. (yes she wants your emails, she reads them, she cares ๐Ÿ’–)


๐Ÿฆ‹ COMMAND SYNOPSIS ๐Ÿฆ‹

This part is just a quick lil' synopsis of sed commands, basically a lil reminder for the people who already know sed. For the fuller descriptions you gotta consult other documentation (like the texinfo document). iykyk.

๐ŸŒˆ Zero-address "commands"

  • : label โ€” Label for b and t commands.
  • #comment โ€” the comment extends until the next newline (or the end of a -e script fragment).
  • } โ€” the closing bracket of a { } block.

๐ŸŒˆ Zero- or One- address commands

  • = โ€” Print the current line number.
  • a \ text โ€” Append text, which has each embedded newline preceded by a backslash.
  • i \ text โ€” Insert text, which has each embedded newline preceded by a backslash.
  • q [exit-code] โ€” Immediately quit the sed script without processing any more input, except that if auto-print is not disabled the current pattern space will be printed. The exit-code argument is a GNU extension.
  • Q [exit-code] โ€” Immediately quit the sed script without processing any more input. This is a GNU extension.
  • r filename โ€” Append text read from filename.
  • R filename โ€” Append a line read from filename. Each invocation of the command reads a line from the file. This is a GNU extension.

๐ŸŒˆ Commands which accept address ranges

  • { โ€” Begin a block of commands (end with a }).
  • b label โ€” Branch to label; if label is omitted, branch to end of script.
  • c \ text โ€” Replace the selected lines with text, which has each embedded newline preceded by a backslash.
  • d โ€” Delete pattern space. Start next cycle.
  • D โ€” If pattern space contains no newline, start a normal new cycle as if the d command was issued. Otherwise, delete text in the pattern space up to the first newline, and restart cycle with the resultant pattern space, without reading a new line of input.
  • h H โ€” Copy/append pattern space to hold space.
  • g G โ€” Copy/append hold space to pattern space.
  • l โ€” List out the current line in a "visually unambiguous" form.
  • l width โ€” List out the current line in a "visually unambiguous" form, breaking it at width characters. This is a GNU extension.
  • n N โ€” Read/append the next line of input into the pattern space.
  • p โ€” Print the current pattern space.
  • P โ€” Print up to the first embedded newline of the current pattern space.
  • s/regexp/replacement/ โ€” Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp.
  • t label โ€” If a s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script.
  • T label โ€” If no s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script. This is a GNU extension.
  • w filename โ€” Write the current pattern space to filename.
  • W filename โ€” Write the first line of the current pattern space to filename. This is a GNU extension.
  • x โ€” Exchange the contents of the hold and pattern spaces.
  • y/source/dest/ โ€” Transliterate the characters in the pattern space which appear in source to the corresponding character in dest.

๐ŸŒˆ Addresses

Sed commands can be given with no addresses, in which case the command gets executed for all input lines. With one address, the command only gets executed for input lines that match that address. Or with two addresses, in which case the command gets executed for all input lines that match the inclusive range of lines starting from the first address and continuing to the second address. ๐ŸŽฏ

Three things to note about address ranges, bestie, don't skip this:

  1. the syntax is addr1,addr2 (i.e., the addresses are separated by a comma);
  2. the line which addr1 matched will always be accepted, even if addr2 selects an earlier line;
  3. and if addr2 is a regexp, it will not be tested against the line that addr1 matched.

After the address (or address-range), and before the command, a ! may be inserted, which specifies that the command shall only be executed if the address (or address-range) does not match.

The following address types are supported:

  • number โ€” Match only the specified line number (which increments cumulatively across files, unless the -s option is specified on the command line).
  • first~step โ€” Match every step'th line starting with line first. For example, sed -n 1~2p will print all the odd-numbered lines in the input stream, and the address 2~5 will match every fifth line, starting with the second. first can be zero; in this case, sed operates as if it were equal to step. (This is an extension.)
  • $ โ€” Match the last line.
  • /regexp/ โ€” Match lines matching the regular expression regexp. Matching is performed on the current pattern space, which can be modified with commands such as s///.
  • \cregexpc โ€” Match lines matching the regular expression regexp. The c may be any character.

GNU sed also supports some special 2-address forms:

  • 0,addr2 โ€” Start out in "matched first address" state, until addr2 is found. This is similar to 1,addr2, except that if addr2 matches the very first line of input the 0,addr2 form will be at the end of its range, whereas the 1,addr2 form will still be at the beginning of its range. This works only when addr2 is a regular expression.
  • addr1,+N โ€” Will match addr1 and the N lines following addr1.
  • addr1,~N โ€” Will match addr1 and the lines following addr1 until the next line whose input line number is a multiple of N.

๐Ÿ’œ REGULAR EXPRESSIONS ๐Ÿ’œ

POSIX.2 BREs should be supported, but they aren't completely, because of performance problems. ๐Ÿ˜ญ The \n sequence in a regular expression matches the newline character, and similarly for \a, \t, and other sequences. The -E option switches to using extended regular expressions instead; it has been supported for years by GNU sed, and is now included in POSIX. glow up fr fr โœจ


๐Ÿ’€ BUGS ๐Ÿ’€

E-mail bug reports to bug-sed@gnu.org. Also, please include the output of sed --version in the body of your report if at all possible. (she's begging, she needs the version info, help her out ๐Ÿ™ˆ)


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Written by Jay Fenlason, Tom Lord, Ken Pizzini, Paolo Bonzini, Jim Meyering, and Assaf Gordon. legends, all of them ๐Ÿซถ

This sed program was built without SELinux support.

GNU sed home page: <https://www.gnu.org/software/sed/>. General help using GNU software: <https://www.gnu.org/gethelp/>. E-mail bug reports to: <bug-sed@gnu.org>.


Copyright ยฉ 2026 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

no warranty bestie, she's free and she's yours to remix, but she comes as-is ๐Ÿ’…

๐ŸŒŸ SEE ALSO ๐ŸŒŸ

awk(1), ed(1), grep(1), tr(1), perlre(1), sed.info, any of various books on sed, the sed FAQ (<http://sed.sf.net/grabbag/tutorials/sedfaq.txt>), <http://sed.sf.net/grabbag/>.

The full documentation for sed is maintained as a Texinfo manual. If the info and sed programs are properly installed at your site, the command

info sed

should give you access to the complete manual.


okay that's the whole page, and this was GNU sed 4.10, dated August 2026 โ€” mwah, love that for her. now go filter some text, you absolute icon ๐Ÿ’–โœจ๐Ÿฆ‹๐ŸŒธ

๐Ÿ“ฆ where this page comes from