{
    "content": [
        {
            "type": "text",
            "text": "# sed (man)\n\n## NAME\n\nsed - stream editor for filtering and transforming text\n\n## SYNOPSIS\n\nsed [-V] [--version] [--help] [-n] [--quiet] [--silent]\n[-l N] [--line-length=N] [-u] [--unbuffered]\n[-E] [-r] [--regexp-extended]\n[-e script] [--expression=script]\n[-f script-file] [--file=script-file]\n[script-if-no-other-script]\n[file...]\n\n## DESCRIPTION\n\nSed  is a stream editor.  A stream editor is used to perform basic text transformations on an\ninput stream (a file or input from a pipeline).  While in some  ways  similar  to  an  editor\nwhich  permits  scripted  edits  (such as ed), sed works by making only one pass over the in‐\nput(s), and is consequently more efficient.  But it is sed's ability  to  filter  text  in  a\npipeline which particularly distinguishes it from other types of editors.\n\n## TLDR\n\n> Edit text in a scriptable manner.\n\n- Replace all `apple` (basic `regex`) occurrences with `mango` (basic `regex`) in all input lines and print the result to `stdout`:\n  `{{command}} | sed 's/apple/mango/g'`\n- Execute a specific script [f]ile and print the result to `stdout`:\n  `{{command}} | sed -f {{path/to/script.sed}}`\n- Print just a first line to `stdout`:\n  `{{command}} | sed -n '1p'`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (15 subsections)\n- **COMMAND SYNOPSIS** (3 subsections)\n- **Addresses**\n- **REGULAR EXPRESSIONS**\n- **BUGS**\n- **AUTHOR**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "sed",
        "section": "",
        "mode": "man",
        "summary": "sed - stream editor for filtering and transforming text",
        "synopsis": "sed [-V] [--version] [--help] [-n] [--quiet] [--silent]\n[-l N] [--line-length=N] [-u] [--unbuffered]\n[-E] [-r] [--regexp-extended]\n[-e script] [--expression=script]\n[-f script-file] [--file=script-file]\n[script-if-no-other-script]\n[file...]",
        "tldr_summary": "Edit text in a scriptable manner.",
        "tldr_examples": [
            {
                "description": "Replace all `apple` (basic `regex`) occurrences with `mango` (basic `regex`) in all input lines and print the result to `stdout`",
                "command": "{{command}} | sed 's/apple/mango/g'"
            },
            {
                "description": "Execute a specific script [f]ile and print the result to `stdout`",
                "command": "{{command}} | sed -f {{path/to/script.sed}}"
            },
            {
                "description": "Print just a first line to `stdout`",
                "command": "{{command}} | sed -n '1p'"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-n",
                "long": "--silent",
                "arg": null,
                "description": "suppress automatic printing of pattern space"
            },
            {
                "flag": "",
                "long": "--debug",
                "arg": null,
                "description": "annotate program execution"
            },
            {
                "flag": "-e",
                "long": "--expression",
                "arg": null,
                "description": "add the script to the commands to be executed"
            },
            {
                "flag": "-f",
                "long": "--file",
                "arg": null,
                "description": "add the contents of script-file to the commands to be executed"
            },
            {
                "flag": "",
                "long": "--follow-symlinks",
                "arg": null,
                "description": "follow symlinks when processing in place"
            },
            {
                "flag": "",
                "long": "--in-place",
                "arg": null,
                "description": "edit files in place (makes backup if SUFFIX supplied)"
            },
            {
                "flag": "-l",
                "long": "--line-length",
                "arg": null,
                "description": "specify the desired line-wrap length for the `l' command"
            },
            {
                "flag": "",
                "long": "--posix",
                "arg": null,
                "description": "disable all GNU extensions."
            },
            {
                "flag": "-r",
                "long": "--regexp-extended",
                "arg": null,
                "description": "use extended regular expressions in the script (for portability use POSIX -E)."
            },
            {
                "flag": "-s",
                "long": "--separate",
                "arg": null,
                "description": "consider files as separate rather than as a single, continuous long stream."
            },
            {
                "flag": "",
                "long": "--sandbox",
                "arg": null,
                "description": "operate in sandbox mode (disable e/r/w commands)."
            },
            {
                "flag": "-u",
                "long": "--unbuffered",
                "arg": null,
                "description": "load minimal amounts of data from the input files and flush the output buffers more often"
            },
            {
                "flag": "-z",
                "long": "--null-data",
                "arg": null,
                "description": "separate lines by NUL characters"
            },
            {
                "flag": "",
                "long": "--help",
                "arg": null,
                "description": "display this help and exit"
            },
            {
                "flag": "",
                "long": "--version",
                "arg": null,
                "description": "output version information and exit If no -e, --expression, -f, or --file option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the standard input is read. 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>. Packaged by Debian Copyright © 2022 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."
            }
        ],
        "examples": [],
        "see_also": [
            {
                "name": "awk",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/awk/1/json"
            },
            {
                "name": "ed",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/ed/1/json"
            },
            {
                "name": "grep",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/grep/1/json"
            },
            {
                "name": "tr",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/tr/1/json"
            },
            {
                "name": "perlre",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/perlre/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 6,
                "subsections": [
                    {
                        "name": "-n --quiet --silent",
                        "lines": 2,
                        "flag": "-n",
                        "long": "--silent"
                    },
                    {
                        "name": "--debug",
                        "lines": 2,
                        "long": "--debug"
                    },
                    {
                        "name": "-e  --expression",
                        "lines": 2,
                        "flag": "-e",
                        "long": "--expression"
                    },
                    {
                        "name": "-f  --file",
                        "lines": 2,
                        "flag": "-f",
                        "long": "--file"
                    },
                    {
                        "name": "--follow-symlinks",
                        "lines": 2,
                        "long": "--follow-symlinks"
                    },
                    {
                        "name": "-i[SUFFIX] --in-place",
                        "lines": 2,
                        "long": "--in-place"
                    },
                    {
                        "name": "-l  --line-length",
                        "lines": 2,
                        "flag": "-l",
                        "long": "--line-length"
                    },
                    {
                        "name": "--posix",
                        "lines": 2,
                        "long": "--posix"
                    },
                    {
                        "name": "-E -r --regexp-extended",
                        "lines": 2,
                        "flag": "-r",
                        "long": "--regexp-extended"
                    },
                    {
                        "name": "-s --separate",
                        "lines": 2,
                        "flag": "-s",
                        "long": "--separate"
                    },
                    {
                        "name": "--sandbox",
                        "lines": 2,
                        "long": "--sandbox"
                    },
                    {
                        "name": "-u --unbuffered",
                        "lines": 3,
                        "flag": "-u",
                        "long": "--unbuffered"
                    },
                    {
                        "name": "-z --null-data",
                        "lines": 2,
                        "flag": "-z",
                        "long": "--null-data"
                    },
                    {
                        "name": "--help",
                        "lines": 2,
                        "long": "--help"
                    },
                    {
                        "name": "--version",
                        "lines": 13,
                        "long": "--version"
                    }
                ]
            },
            {
                "name": "COMMAND SYNOPSIS",
                "lines": 4,
                "subsections": [
                    {
                        "name": "Zero-address ``commands''",
                        "lines": 8
                    },
                    {
                        "name": "Zero- or One- address commands",
                        "lines": 26
                    },
                    {
                        "name": "Commands which accept address ranges",
                        "lines": 61
                    }
                ]
            },
            {
                "name": "Addresses",
                "lines": 48,
                "subsections": []
            },
            {
                "name": "REGULAR EXPRESSIONS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 11,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "sed - stream editor for filtering and transforming text\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "sed [-V] [--version] [--help] [-n] [--quiet] [--silent]\n[-l N] [--line-length=N] [-u] [--unbuffered]\n[-E] [-r] [--regexp-extended]\n[-e script] [--expression=script]\n[-f script-file] [--file=script-file]\n[script-if-no-other-script]\n[file...]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Sed  is a stream editor.  A stream editor is used to perform basic text transformations on an\ninput stream (a file or input from a pipeline).  While in some  ways  similar  to  an  editor\nwhich  permits  scripted  edits  (such as ed), sed works by making only one pass over the in‐\nput(s), and is consequently more efficient.  But it is sed's ability  to  filter  text  in  a\npipeline which particularly distinguishes it from other types of editors.\n",
                "subsections": [
                    {
                        "name": "-n --quiet --silent",
                        "content": "suppress automatic printing of pattern space\n",
                        "flag": "-n",
                        "long": "--silent"
                    },
                    {
                        "name": "--debug",
                        "content": "annotate program execution\n",
                        "long": "--debug"
                    },
                    {
                        "name": "-e  --expression",
                        "content": "add the script to the commands to be executed\n",
                        "flag": "-e",
                        "long": "--expression"
                    },
                    {
                        "name": "-f  --file",
                        "content": "add the contents of script-file to the commands to be executed\n",
                        "flag": "-f",
                        "long": "--file"
                    },
                    {
                        "name": "--follow-symlinks",
                        "content": "follow symlinks when processing in place\n",
                        "long": "--follow-symlinks"
                    },
                    {
                        "name": "-i[SUFFIX] --in-place",
                        "content": "edit files in place (makes backup if SUFFIX supplied)\n",
                        "long": "--in-place"
                    },
                    {
                        "name": "-l  --line-length",
                        "content": "specify the desired line-wrap length for the `l' command\n",
                        "flag": "-l",
                        "long": "--line-length"
                    },
                    {
                        "name": "--posix",
                        "content": "disable all GNU extensions.\n",
                        "long": "--posix"
                    },
                    {
                        "name": "-E -r --regexp-extended",
                        "content": "use extended regular expressions in the script (for portability use POSIX -E).\n",
                        "flag": "-r",
                        "long": "--regexp-extended"
                    },
                    {
                        "name": "-s --separate",
                        "content": "consider files as separate rather than as a single, continuous long stream.\n",
                        "flag": "-s",
                        "long": "--separate"
                    },
                    {
                        "name": "--sandbox",
                        "content": "operate in sandbox mode (disable e/r/w commands).\n",
                        "long": "--sandbox"
                    },
                    {
                        "name": "-u --unbuffered",
                        "content": "load  minimal  amounts  of data from the input files and flush the output buffers more\noften\n",
                        "flag": "-u",
                        "long": "--unbuffered"
                    },
                    {
                        "name": "-z --null-data",
                        "content": "separate lines by NUL characters\n",
                        "flag": "-z",
                        "long": "--null-data"
                    },
                    {
                        "name": "--help",
                        "content": "display this help and exit\n",
                        "long": "--help"
                    },
                    {
                        "name": "--version",
                        "content": "output version information and exit\n\nIf no -e, --expression, -f, or --file option is given, then the first non-option argument  is\ntaken  as  the sed script to interpret.  All remaining arguments are names of input files; if\nno input files are specified, then the standard input is read.\n\nGNU sed home page: <https://www.gnu.org/software/sed/>.  General  help  using  GNU  software:\n<https://www.gnu.org/gethelp/>.  E-mail bug reports to: <bug-sed@gnu.org>.\n\nPackaged  by  Debian Copyright © 2022 Free Software Foundation, Inc.  License GPLv3+: GNU GPL\nversion 3 or later <https://gnu.org/licenses/gpl.html>.  This is free software: you are  free\nto change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.\n",
                        "long": "--version"
                    }
                ]
            },
            "COMMAND SYNOPSIS": {
                "content": "This  is  just  a  brief synopsis of sed commands to serve as a reminder to those who already\nknow sed; other documentation (such as the texinfo document) must be consulted for fuller de‐\nscriptions.\n",
                "subsections": [
                    {
                        "name": "Zero-address ``commands''",
                        "content": ": label\nLabel for b and t commands.\n\n#comment\nThe comment extends until the next newline (or the end of a -e script fragment).\n\n}      The closing bracket of a { } block.\n"
                    },
                    {
                        "name": "Zero- or One- address commands",
                        "content": "=      Print the current line number.\n\na \\\n\ntext   Append text, which has each embedded newline preceded by a backslash.\n\ni \\\n\ntext   Insert text, which has each embedded newline preceded by a backslash.\n\nq [exit-code]\nImmediately quit the sed script without processing any  more  input,  except  that  if\nauto-print  is  not disabled the current pattern space will be printed.  The exit code\nargument is a GNU extension.\n\nQ [exit-code]\nImmediately quit the sed script without processing any more input.  This is a GNU  ex‐\ntension.\n\nr filename\nAppend text read from filename.\n\nR filename\nAppend  a  line  read from filename.  Each invocation of the command reads a line from\nthe file.  This is a GNU extension.\n"
                    },
                    {
                        "name": "Commands which accept address ranges",
                        "content": "{      Begin a block of commands (end with a }).\n\nb label\nBranch to label; if label is omitted, branch to end of script.\n\nc \\\n\ntext   Replace the selected lines with text, which has each embedded newline  preceded  by  a\nbackslash.\n\nd      Delete pattern space.  Start next cycle.\n\nD      If pattern space contains no newline, start a normal new cycle as if the d command was\nissued.   Otherwise,  delete  text  in  the pattern space up to the first newline, and\nrestart cycle with the resultant pattern space, without reading a new line of input.\n\nh H    Copy/append pattern space to hold space.\n\ng G    Copy/append hold space to pattern space.\n\nl      List out the current line in a ``visually unambiguous'' form.\n\nl width\nList out the current line in a ``visually unambiguous'' form,  breaking  it  at  width\ncharacters.  This is a GNU extension.\n\nn N    Read/append the next line of input into the pattern space.\n\np      Print the current pattern space.\n\nP      Print up to the first embedded newline of the current pattern space.\n\ns/regexp/replacement/\nAttempt  to  match regexp against the pattern space.  If successful, replace that por‐\ntion matched with replacement.  The replacement may contain the special character & to\nrefer to that portion of the pattern space which matched, and the special  escapes  \\1\nthrough \\9 to refer to the corresponding matching sub-expressions in the regexp.\n\nt label\nIf  a  s///  has done a successful substitution since the last input line was read and\nsince the last t or T command, then branch to label; if label is  omitted,  branch  to\nend of script.\n\nT label\nIf  no  s/// has done a successful substitution since the last input line was read and\nsince the last t or T command, then branch to label; if label is  omitted,  branch  to\nend of script.  This is a GNU extension.\n\nw filename\nWrite the current pattern space to filename.\n\nW filename\nWrite  the  first line of the current pattern space to filename.  This is a GNU exten‐\nsion.\n\nx      Exchange the contents of the hold and pattern spaces.\n\ny/source/dest/\nTransliterate the characters in the pattern space which appear in source to the corre‐\nsponding character in dest.\n"
                    }
                ]
            },
            "Addresses": {
                "content": "Sed commands can be given with no addresses, in which case the command will be  executed  for\nall  input lines; with one address, in which case the command will only be executed for input\nlines which match that address; or with two addresses, in which case the command will be exe‐\ncuted for all input lines which match the inclusive range of lines starting  from  the  first\naddress and continuing to the second address.  Three things to note about address ranges: the\nsyntax  is  addr1,addr2  (i.e., the addresses are separated by a comma); the line which addr1\nmatched will always be accepted, even if addr2 selects an earlier line; and  if  addr2  is  a\nregexp, it will not be tested against the line that addr1 matched.\n\nAfter  the  address  (or  address-range), and before the command, a !  may be inserted, which\nspecifies that the command shall only be executed if the address (or address-range) does  not\nmatch.\n\nThe following address types are supported:\n\nnumber Match  only the specified line number (which increments cumulatively across files, un‐\nless the -s option is specified on the command line).\n\nfirst~step\nMatch every step'th line starting with line first.  For example, ``sed -n 1~2p''  will\nprint  all  the odd-numbered lines in the input stream, and the address 2~5 will match\nevery fifth line, starting with the second.  first can be zero; in this case, sed  op‐\nerates as if it were equal to step.  (This is an extension.)\n\n$      Match the last line.\n\n/regexp/\nMatch lines matching the regular expression regexp.  Matching is performed on the cur‐\nrent pattern space, which can be modified with commands such as ``s///''.\n\n\\cregexpc\nMatch lines matching the regular expression regexp.  The c may be any character.\n\nGNU sed also supports some special 2-address forms:\n\n0,addr2\nStart  out in \"matched first address\" state, until addr2 is found.  This is similar to\n1,addr2, except that if addr2 matches the very first line of input  the  0,addr2  form\nwill  be at the end of its range, whereas the 1,addr2 form will still be at the begin‐\nning of its range.  This works only when addr2 is a regular expression.\n\naddr1,+N\nWill match addr1 and the N lines following addr1.\n\naddr1,~N\nWill match addr1 and the lines following addr1 until the next line  whose  input  line\nnumber is a multiple of N.\n",
                "subsections": []
            },
            "REGULAR EXPRESSIONS": {
                "content": "POSIX.2 BREs should be supported, but they aren't completely because of performance problems.\nThe  \\n sequence in a regular expression matches the newline character, and similarly for \\a,\n\\t, and other sequences.  The -E option switches to using extended  regular  expressions  in‐\nstead; it has been supported for years by GNU sed, and is now included in POSIX.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "E-mail  bug reports to bug-sed@gnu.org.  Also, please include the output of ``sed --version''\nin the body of your report if at all possible.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Written by Jay Fenlason, Tom Lord, Ken Pizzini, Paolo Bonzini, Jim Meyering, and  Assaf  Gor‐\ndon.\n\nThis sed program was built with SELinux support.  SELinux is disabled on this system.\n\nGNU  sed  home  page:  <https://www.gnu.org/software/sed/>.  General help using GNU software:\n<https://www.gnu.org/gethelp/>.  E-mail bug reports to: <bug-sed@gnu.org>.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "awk(1), ed(1), grep(1), tr(1), perlre(1), sed.info, any of various books on sed, the sed FAQ\n(http://sed.sf.net/grabbag/tutorials/sedfaq.txt), http://sed.sf.net/grabbag/.\n\nThe full documentation for sed is maintained as a Texinfo manual.  If the info and sed pro‐\ngrams are properly installed at your site, the command\n\ninfo sed\n\nshould give you access to the complete manual.\n\nGNU sed 4.9                                  April 2026                                       SED(1)",
                "subsections": []
            }
        }
    }
}