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 thelcommand.--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 thee/r/wcommands).-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 forbandtcommands.#commentโ the comment extends until the next newline (or the end of a-escript 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 thedcommand 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\1through\9to refer to the corresponding matching sub-expressions in the regexp.t labelโ If as///has done a successful substitution since the last input line was read and since the lasttorTcommand, then branch to label; if label is omitted, branch to end of script.T labelโ If nos///has done a successful substitution since the last input line was read and since the lasttorTcommand, 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:
- the syntax is
addr1,addr2(i.e., the addresses are separated by a comma); - the line which addr1 matched will always be accepted, even if addr2 selects an earlier line;
- 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-soption is specified on the command line).first~stepโ Match every step'th line starting with line first. For example,sed -n 1~2pwill print all the odd-numbered lines in the input stream, and the address2~5will 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 ass///.\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 to1,addr2, except that if addr2 matches the very first line of input the0,addr2form will be at the end of its range, whereas the1,addr2form 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 ๐
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
- arch rolling: sed 4.10-2 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms