{
    "mode": "info",
    "parameter": "sed",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/sed/json",
    "generated": "2026-06-08T12:12:37Z",
    "sections": {
        "GNU 'sed'": {
            "content": "This file documents version 4.8 of GNU 'sed', a stream editor.\n\nCopyright (C) 1998-2020 Free Software Foundation, Inc.\n\nPermission is granted to copy, distribute and/or modify this\ndocument under the terms of the GNU Free Documentation License,\nVersion 1.3 or any later version published by the Free Software\nFoundation; with no Invariant Sections, no Front-Cover Texts, and\nno Back-Cover Texts.  A copy of the license is included in the\nsection entitled \"GNU Free Documentation License\".\n\n* Menu:\n\n* Introduction::               Introduction\n* Invoking sed::               Invocation\n* sed scripts::                'sed' scripts\n* sed addresses::              Addresses: selecting lines\n* sed regular expressions::    Regular expressions: selecting text\n* advanced sed::               Advanced 'sed': cycles and buffers\n* Examples::                   Some sample scripts\n* Limitations::                Limitations and (non-)limitations of GNU 'sed'\n* Other Resources::            Other resources for learning about 'sed'\n* Reporting Bugs::             Reporting bugs\n* GNU Free Documentation License:: Copying and sharing this manual\n* Concept Index::              A menu with all the topics in this manual.\n* Command and Option Index::   A menu with all 'sed' commands and\ncommand-line options.\n\nFile: sed.info,  Node: Introduction,  Next: Invoking sed,  Prev: Top,  Up: Top\n",
            "subsections": []
        },
        "1 Introduction": {
            "content": "'sed' is a stream editor.  A stream editor is used to perform basic text\ntransformations on an input stream (a file or input from a pipeline).\nWhile in some ways similar to an editor which permits scripted edits\n(such as 'ed'), 'sed' works by making only one pass over the input(s),\nand is consequently more efficient.  But it is 'sed''s ability to filter\ntext in a pipeline which particularly distinguishes it from other types\nof editors.\n\nFile: sed.info,  Node: Invoking sed,  Next: sed scripts,  Prev: Introduction,  Up: Top\n",
            "subsections": []
        },
        "2 Running sed": {
            "content": "This chapter covers how to run 'sed'.  Details of 'sed' scripts and\nindividual 'sed' commands are discussed in the next chapter.\n\n* Menu:\n\n* Overview::\n* Command-Line Options::\n* Exit status::\n\nFile: sed.info,  Node: Overview,  Next: Command-Line Options,  Up: Invoking sed\n",
            "subsections": [
                {
                    "name": "2.1 Overview",
                    "content": "Normally 'sed' is invoked like this:\n\nsed SCRIPT INPUTFILE...\n\nFor example, to replace all occurrences of 'hello' to 'world' in the\nfile 'input.txt':\n\nsed 's/hello/world/' input.txt > output.txt\n\nIf you do not specify INPUTFILE, or if INPUTFILE is '-', 'sed'\nfilters the contents of the standard input.  The following commands are\nequivalent:\n\nsed 's/hello/world/' input.txt > output.txt\nsed 's/hello/world/' < input.txt > output.txt\ncat input.txt | sed 's/hello/world/' - > output.txt\n\n'sed' writes output to standard output.  Use '-i' to edit files\nin-place instead of printing to standard output.  See also the 'W' and\n's///w' commands for writing output to other files.  The following\ncommand modifies 'file.txt' and does not produce any output:\n\nsed -i 's/hello/world/' file.txt\n\nBy default 'sed' prints all processed input (except input that has\nbeen modified/deleted by commands such as 'd').  Use '-n' to suppress\noutput, and the 'p' command to print specific lines.  The following\ncommand prints only line 45 of the input file:\n\nsed -n '45p' file.txt\n\n'sed' treats multiple input files as one long stream.  The following\nexample prints the first line of the first file ('one.txt') and the last\nline of the last file ('three.txt').  Use '-s' to reverse this behavior.\n\nsed -n  '1p ; $p' one.txt two.txt three.txt\n\nWithout '-e' or '-f' options, 'sed' uses the first non-option\nparameter as the SCRIPT, and the following non-option parameters as\ninput files.  If '-e' or '-f' options are used to specify a SCRIPT, all\nnon-option parameters are taken as input files.  Options '-e' and '-f'\ncan be combined, and can appear multiple times (in which case the final\neffective SCRIPT will be concatenation of all the individual SCRIPTs).\n\nThe following examples are equivalent:\n\nsed 's/hello/world/' input.txt > output.txt\n\nsed -e 's/hello/world/' input.txt > output.txt\nsed --expression='s/hello/world/' input.txt > output.txt\n\necho 's/hello/world/' > myscript.sed\nsed -f myscript.sed input.txt > output.txt\nsed --file=myscript.sed input.txt > output.txt\n\nFile: sed.info,  Node: Command-Line Options,  Next: Exit status,  Prev: Overview,  Up: Invoking sed\n"
                },
                {
                    "name": "2.2 Command-Line Options",
                    "content": "The full format for invoking 'sed' is:\n\nsed OPTIONS... [SCRIPT] [INPUTFILE...]\n\n'sed' may be invoked with the following command-line options:\n\n'--version'\nPrint out the version of 'sed' that is being run and a copyright\nnotice, then exit.\n\n'--help'\nPrint a usage message briefly summarizing these command-line\noptions and the bug-reporting address, then exit.\n\n'-n'\n'--quiet'\n'--silent'\nBy default, 'sed' prints out the pattern space at the end of each\ncycle through the script (*note How 'sed' works: Execution Cycle.).\nThese options disable this automatic printing, and 'sed' only\nproduces output when explicitly told to via the 'p' command.\n\n'--debug'\nPrint the input sed program in canonical form, and annotate program\nexecution.\n$ echo 1 | sed '\\%1%s21232'\n3\n\n$ echo 1 | sed --debug '\\%1%s21232'\nSED PROGRAM:\n/1/ s/1/3/\nINPUT:   'STDIN' line 1\nPATTERN: 1\nCOMMAND: /1/ s/1/3/\nPATTERN: 3\nEND-OF-CYCLE:\n3\n\n'-e SCRIPT'\n'--expression=SCRIPT'\nAdd the commands in SCRIPT to the set of commands to be run while\nprocessing the input.\n\n'-f SCRIPT-FILE'\n'--file=SCRIPT-FILE'\nAdd the commands contained in the file SCRIPT-FILE to the set of\ncommands to be run while processing the input.\n\n'-i[SUFFIX]'\n'--in-place[=SUFFIX]'\nThis option specifies that files are to be edited in-place.  GNU\n'sed' does this by creating a temporary file and sending output to\nthis file rather than to the standard output.(1).\n\nThis option implies '-s'.\n\nWhen the end of the file is reached, the temporary file is renamed\nto the output file's original name.  The extension, if supplied, is\nused to modify the name of the old file before renaming the\ntemporary file, thereby making a backup copy(2)).\n\nThis rule is followed: if the extension doesn't contain a '*', then\nit is appended to the end of the current filename as a suffix; if\nthe extension does contain one or more '*' characters, then each\nasterisk is replaced with the current filename.  This allows you to\nadd a prefix to the backup file, instead of (or in addition to) a\nsuffix, or even to place backup copies of the original files into\nanother directory (provided the directory already exists).\n\nIf no extension is supplied, the original file is overwritten\nwithout making a backup.\n\nBecause '-i' takes an optional argument, it should not be followed\nby other short options:\n'sed -Ei '...' FILE'\nSame as '-E -i' with no backup suffix - 'FILE' will be edited\nin-place without creating a backup.\n\n'sed -iE '...' FILE'\nThis is equivalent to '--in-place=E', creating 'FILEE' as\nbackup of 'FILE'\n\nBe cautious of using '-n' with '-i': the former disables automatic\nprinting of lines and the latter changes the file in-place without\na backup.  Used carelessly (and without an explicit 'p' command),\nthe output file will be empty:\n# WRONG USAGE: 'FILE' will be truncated.\nsed -ni 's/foo/bar/' FILE\n\n'-l N'\n'--line-length=N'\nSpecify the default line-wrap length for the 'l' command.  A length\nof 0 (zero) means to never wrap long lines.  If not specified, it\nis taken to be 70.\n\n'--posix'\nGNU 'sed' includes several extensions to POSIX sed.  In order to\nsimplify writing portable scripts, this option disables all the\nextensions that this manual documents, including additional\ncommands.  Most of the extensions accept 'sed' programs that are\noutside the syntax mandated by POSIX, but some of them (such as the\nbehavior of the 'N' command described in *note Reporting Bugs::)\nactually violate the standard.  If you want to disable only the\nlatter kind of extension, you can set the 'POSIXLYCORRECT'\nvariable to a non-empty value.\n\n'-b'\n'--binary'\nThis option is available on every platform, but is only effective\nwhere the operating system makes a distinction between text files\nand binary files.  When such a distinction is made--as is the case\nfor MS-DOS, Windows, Cygwin--text files are composed of lines\nseparated by a carriage return and a line feed character, and\n'sed' does not see the ending CR. When this option is specified,\n'sed' will open input files in binary mode, thus not requesting\nthis special processing and considering lines to end at a line\nfeed.\n\n'--follow-symlinks'\nThis option is available only on platforms that support symbolic\nlinks and has an effect only if option '-i' is specified.  In this\ncase, if the file that is specified on the command line is a\nsymbolic link, 'sed' will follow the link and edit the ultimate\ndestination of the link.  The default behavior is to break the\nsymbolic link, so that the link destination will not be modified.\n\n'-E'\n'-r'\n'--regexp-extended'\nUse extended regular expressions rather than basic regular\nexpressions.  Extended regexps are those that 'egrep' accepts; they\ncan be clearer because they usually have fewer backslashes.\nHistorically this was a GNU extension, but the '-E' extension has\nsince been added to the POSIX standard\n(http://austingroupbugs.net/view.php?id=528), so use '-E' for\nportability.  GNU sed has accepted '-E' as an undocumented option\nfor years, and *BSD seds have accepted '-E' for years as well, but\nscripts that use '-E' might not port to other older systems.  *Note\nExtended regular expressions: ERE syntax.\n\n'-s'\n'--separate'\nBy default, 'sed' will consider the files specified on the command\nline as a single continuous long stream.  This GNU 'sed' extension\nallows the user to consider them as separate files: range addresses\n(such as '/abc/,/def/') are not allowed to span several files, line\nnumbers are relative to the start of each file, '$' refers to the\nlast line of each file, and files invoked from the 'R' commands are\nrewound at the start of each file.\n\n'--sandbox'\nIn sandbox mode, 'e/w/r' commands are rejected - programs\ncontaining them will be aborted without being run.  Sandbox mode\nensures 'sed' operates only on the input files designated on the\ncommand line, and cannot run external programs.\n\n'-u'\n'--unbuffered'\nBuffer both input and output as minimally as practical.  (This is\nparticularly useful if the input is coming from the likes of 'tail\n-f', and you wish to see the transformed output as soon as\npossible.)\n\n'-z'\n'--null-data'\n'--zero-terminated'\nTreat the input as a set of lines, each terminated by a zero byte\n(the ASCII 'NUL' character) instead of a newline.  This option can\nbe used with commands like 'sort -z' and 'find -print0' to process\narbitrary file names.\n\nIf no '-e', '-f', '--expression', or '--file' options are given on\nthe command-line, then the first non-option argument on the command line\nis taken to be the SCRIPT to be executed.\n\nIf any command-line parameters remain after processing the above,\nthese parameters are interpreted as the names of input files to be\nprocessed.  A file name of '-' refers to the standard input stream.  The\nstandard input will be processed if no file names are specified.\n\n---------- Footnotes ----------\n\n(1) This applies to commands such as '=', 'a', 'c', 'i', 'l', 'p'.\nYou can still write to the standard output by using the 'w' or 'W'\ncommands together with the '/dev/stdout' special file\n\n(2) Note that GNU 'sed' creates the backup file whether or not any\noutput is actually changed.\n\nFile: sed.info,  Node: Exit status,  Prev: Command-Line Options,  Up: Invoking sed\n"
                },
                {
                    "name": "2.3 Exit status",
                    "content": "An exit status of zero indicates success, and a nonzero value indicates\nfailure.  GNU 'sed' returns the following exit status error values:\n\n0\nSuccessful completion.\n\n1\nInvalid command, invalid syntax, invalid regular expression or a\nGNU 'sed' extension command used with '--posix'.\n\n2\nOne or more of the input file specified on the command line could\nnot be opened (e.g.  if a file is not found, or read permission is\ndenied).  Processing continued with other files.\n\n4\nAn I/O error, or a serious processing error during runtime, GNU\n'sed' aborted immediately.\n\nAdditionally, the commands 'q' and 'Q' can be used to terminate 'sed'\nwith a custom exit code value (this is a GNU 'sed' extension):\n\n$ echo | sed 'Q42' ; echo $?\n42\n\nFile: sed.info,  Node: sed scripts,  Next: sed addresses,  Prev: Invoking sed,  Up: Top\n"
                }
            ]
        },
        "3 'sed' scripts": {
            "content": "* Menu:\n\n* sed script overview::      'sed' script overview\n* sed commands list::        'sed' commands summary\n* The \"s\" Command::          'sed''s Swiss Army Knife\n* Common Commands::          Often used commands\n* Other Commands::           Less frequently used commands\n* Programming Commands::     Commands for 'sed' gurus\n* Extended Commands::        Commands specific of GNU 'sed'\n* Multiple commands syntax:: Extension for easier scripting\n\nFile: sed.info,  Node: sed script overview,  Next: sed commands list,  Up: sed scripts\n",
            "subsections": [
                {
                    "name": "3.1 'sed' script overview",
                    "content": "A 'sed' program consists of one or more 'sed' commands, passed in by one\nor more of the '-e', '-f', '--expression', and '--file' options, or the\nfirst non-option argument if zero of these options are used.  This\ndocument will refer to \"the\" 'sed' script; this is understood to mean\nthe in-order concatenation of all of the SCRIPTs and SCRIPT-FILEs passed\nin.  *Note Overview::.\n\n'sed' commands follow this syntax:\n\n[addr]X[options]\n\nX is a single-letter 'sed' command.  '[addr]' is an optional line\naddress.  If '[addr]' is specified, the command X will be executed only\non the matched lines.  '[addr]' can be a single line number, a regular\nexpression, or a range of lines (*note sed addresses::).  Additional\n'[options]' are used for some 'sed' commands.\n\nThe following example deletes lines 30 to 35 in the input.  '30,35'\nis an address range.  'd' is the delete command:\n\nsed '30,35d' input.txt > output.txt\n\nThe following example prints all input until a line starting with the\nword 'foo' is found.  If such line is found, 'sed' will terminate with\nexit status 42.  If such line was not found (and no other error\noccurred), 'sed' will exit with status 0.  '/^foo/' is a\nregular-expression address.  'q' is the quit command.  '42' is the\ncommand option.\n\nsed '/^foo/q42' input.txt > output.txt\n\nCommands within a SCRIPT or SCRIPT-FILE can be separated by\nsemicolons (';') or newlines (ASCII 10).  Multiple scripts can be\nspecified with '-e' or '-f' options.\n\nThe following examples are all equivalent.  They perform two 'sed'\noperations: deleting any lines matching the regular expression '/^foo/',\nand replacing all occurrences of the string 'hello' with 'world':\n\nsed '/^foo/d ; s/hello/world/' input.txt > output.txt\n\nsed -e '/^foo/d' -e 's/hello/world/' input.txt > output.txt\n\necho '/^foo/d' > script.sed\necho 's/hello/world/' >> script.sed\nsed -f script.sed input.txt > output.txt\n\necho 's/hello/world/' > script2.sed\nsed -e '/^foo/d' -f script2.sed input.txt > output.txt\n\nCommands 'a', 'c', 'i', due to their syntax, cannot be followed by\nsemicolons working as command separators and thus should be terminated\nwith newlines or be placed at the end of a SCRIPT or SCRIPT-FILE.\nCommands can also be preceded with optional non-significant whitespace\ncharacters.  *Note Multiple commands syntax::.\n\nFile: sed.info,  Node: sed commands list,  Next: The \"s\" Command,  Prev: sed script overview,  Up: sed scripts\n"
                },
                {
                    "name": "3.2 'sed' commands summary",
                    "content": "The following commands are supported in GNU 'sed'.  Some are standard\nPOSIX commands, while other are GNU extensions.  Details and examples\nfor each command are in the following sections.  (Mnemonics) are shown\nin parentheses.\n\n'a\\'\n'TEXT'\nAppend TEXT after a line.\n\n'a TEXT'\nAppend TEXT after a line (alternative syntax).\n\n'b LABEL'\nBranch unconditionally to LABEL.  The LABEL may be omitted, in\nwhich case the next cycle is started.\n\n'c\\'\n'TEXT'\nReplace (change) lines with TEXT.\n\n'c TEXT'\nReplace (change) lines with TEXT (alternative syntax).\n\n'd'\nDelete the pattern space; immediately start next cycle.\n\n'D'\nIf pattern space contains newlines, delete text in the pattern\nspace up to the first newline, and restart cycle with the resultant\npattern space, without reading a new line of input.\n\nIf pattern space contains no newline, start a normal new cycle as\nif the 'd' command was issued.\n\n'e'\nExecutes the command that is found in pattern space and replaces\nthe pattern space with the output; a trailing newline is\nsuppressed.\n\n'e COMMAND'\nExecutes COMMAND and sends its output to the output stream.  The\ncommand can run across multiple lines, all but the last ending with\na back-slash.\n\n'F'\n(filename) Print the file name of the current input file (with a\ntrailing newline).\n\n'g'\nReplace the contents of the pattern space with the contents of the\nhold space.\n\n'G'\nAppend a newline to the contents of the pattern space, and then\nappend the contents of the hold space to that of the pattern space.\n\n'h'\n(hold) Replace the contents of the hold space with the contents of\nthe pattern space.\n\n'H'\nAppend a newline to the contents of the hold space, and then append\nthe contents of the pattern space to that of the hold space.\n\n'i\\'\n'TEXT'\ninsert TEXT before a line.\n\n'i TEXT'\ninsert TEXT before a line (alternative syntax).\n\n'l'\nPrint the pattern space in an unambiguous form.\n\n'n'\n(next) If auto-print is not disabled, print the pattern space,\nthen, regardless, replace the pattern space with the next line of\ninput.  If there is no more input then 'sed' exits without\nprocessing any more commands.\n\n'N'\nAdd a newline to the pattern space, then append the next line of\ninput to the pattern space.  If there is no more input then 'sed'\nexits without processing any more commands.\n\n'p'\nPrint the pattern space.\n\n'P'\nPrint the pattern space, up to the first <newline>.\n\n'q[EXIT-CODE]'\n(quit) Exit 'sed' without processing any more commands or input.\n\n'Q[EXIT-CODE]'\n(quit) This command is the same as 'q', but will not print the\ncontents of pattern space.  Like 'q', it provides the ability to\nreturn an exit code to the caller.\n\n'r filename'\nReads file FILENAME.\n\n'R filename'\nQueue a line of FILENAME to be read and inserted into the output\nstream at the end of the current cycle, or when the next input line\nis read.\n\n's/REGEXP/REPLACEMENT/[FLAGS]'\n(substitute) Match the regular-expression against the content of\nthe pattern space.  If found, replace matched string with\nREPLACEMENT.\n\n't LABEL'\n(test) Branch to LABEL only if there has been a successful\n's'ubstitution since the last input line was read or conditional\nbranch was taken.  The LABEL may be omitted, in which case the next\ncycle is started.\n\n'T LABEL'\n(test) Branch to LABEL only if there have been no successful\n's'ubstitutions since the last input line was read or conditional\nbranch was taken.  The LABEL may be omitted, in which case the next\ncycle is started.\n\n'v [VERSION]'\n(version) This command does nothing, but makes 'sed' fail if GNU\n'sed' extensions are not supported, or if the requested version is\nnot available.\n\n'w filename'\nWrite the pattern space to FILENAME.\n\n'W filename'\nWrite to the given filename the portion of the pattern space up to\nthe first newline\n\n'x'\nExchange the contents of the hold and pattern spaces.\n\n'y/src/dst/'\nTransliterate any characters in the pattern space which match any\nof the SOURCE-CHARS with the corresponding character in DEST-CHARS.\n\n'z'\n(zap) This command empties the content of pattern space.\n\n'#'\nA comment, until the next newline.\n\n'{ CMD ; CMD ... }'\nGroup several commands together.\n\n'='\nPrint the current input line number (with a trailing newline).\n\n': LABEL'\nSpecify the location of LABEL for branch commands ('b', 't', 'T').\n\nFile: sed.info,  Node: The \"s\" Command,  Next: Common Commands,  Prev: sed commands list,  Up: sed scripts\n"
                },
                {
                    "name": "3.3 The 's' Command",
                    "content": "The 's' command (as in substitute) is probably the most important in\n'sed' and has a lot of different options.  The syntax of the 's' command\nis 's/REGEXP/REPLACEMENT/FLAGS'.\n\nIts basic concept is simple: the 's' command attempts to match the\npattern space against the supplied regular expression REGEXP; if the\nmatch is successful, then that portion of the pattern space which was\nmatched is replaced with REPLACEMENT.\n\nFor details about REGEXP syntax *note Regular Expression Addresses:\nRegexp Addresses.\n\nThe REPLACEMENT can contain '\\N' (N being a number from 1 to 9,\ninclusive) references, which refer to the portion of the match which is\ncontained between the Nth '\\(' and its matching '\\)'.  Also, the\nREPLACEMENT can contain unescaped '&' characters which reference the\nwhole matched portion of the pattern space.\n\nThe '/' characters may be uniformly replaced by any other single\ncharacter within any given 's' command.  The '/' character (or whatever\nother character is used in its stead) can appear in the REGEXP or\nREPLACEMENT only if it is preceded by a '\\' character.\n\nFinally, as a GNU 'sed' extension, you can include a special sequence\nmade of a backslash and one of the letters 'L', 'l', 'U', 'u', or 'E'.\nThe meaning is as follows:\n\n'\\L'\nTurn the replacement to lowercase until a '\\U' or '\\E' is found,\n\n'\\l'\nTurn the next character to lowercase,\n\n'\\U'\nTurn the replacement to uppercase until a '\\L' or '\\E' is found,\n\n'\\u'\nTurn the next character to uppercase,\n\n'\\E'\nStop case conversion started by '\\L' or '\\U'.\n\nWhen the 'g' flag is being used, case conversion does not propagate\nfrom one occurrence of the regular expression to another.  For example,\nwhen the following command is executed with 'a-b-' in pattern space:\ns/\\(b\\?\\)-/x\\u\\1/g\n\nthe output is 'axxB'.  When replacing the first '-', the '\\u' sequence\nonly affects the empty replacement of '\\1'.  It does not affect the 'x'\ncharacter that is added to pattern space when replacing 'b-' with 'xB'.\n\nOn the other hand, '\\l' and '\\u' do affect the remainder of the\nreplacement text if they are followed by an empty substitution.  With\n'a-b-' in pattern space, the following command:\ns/\\(b\\?\\)-/\\u\\1x/g\n\nwill replace '-' with 'X' (uppercase) and 'b-' with 'Bx'.  If this\nbehavior is undesirable, you can prevent it by adding a '\\E'\nsequence--after '\\1' in this case.\n\nTo include a literal '\\', '&', or newline in the final replacement,\nbe sure to precede the desired '\\', '&', or newline in the REPLACEMENT\nwith a '\\'.\n\nThe 's' command can be followed by zero or more of the following\nFLAGS:\n\n'g'\nApply the replacement to all matches to the REGEXP, not just the\nfirst.\n\n'NUMBER'\nOnly replace the NUMBERth match of the REGEXP.\n\ninteraction in 's' command Note: the POSIX standard does not\nspecify what should happen when you mix the 'g' and NUMBER\nmodifiers, and currently there is no widely agreed upon meaning\nacross 'sed' implementations.  For GNU 'sed', the interaction is\ndefined to be: ignore matches before the NUMBERth, and then match\nand replace all matches from the NUMBERth on.\n\n'p'\nIf the substitution was made, then print the new pattern space.\n\nNote: when both the 'p' and 'e' options are specified, the relative\nordering of the two produces very different results.  In general,\n'ep' (evaluate then print) is what you want, but operating the\nother way round can be useful for debugging.  For this reason, the\ncurrent version of GNU 'sed' interprets specially the presence of\n'p' options both before and after 'e', printing the pattern space\nbefore and after evaluation, while in general flags for the 's'\ncommand show their effect just once.  This behavior, although\ndocumented, might change in future versions.\n\n'w FILENAME'\nIf the substitution was made, then write out the result to the\nnamed file.  As a GNU 'sed' extension, two special values of\nFILENAME are supported: '/dev/stderr', which writes the result to\nthe standard error, and '/dev/stdout', which writes to the standard\noutput.(1)\n\n'e'\nThis command allows one to pipe input from a shell command into\npattern space.  If a substitution was made, the command that is\nfound in pattern space is executed and pattern space is replaced\nwith its output.  A trailing newline is suppressed; results are\nundefined if the command to be executed contains a NUL character.\nThis is a GNU 'sed' extension.\n\n'I'\n'i'\nThe 'I' modifier to regular-expression matching is a GNU extension\nwhich makes 'sed' match REGEXP in a case-insensitive manner.\n\n'M'\n'm'\nThe 'M' modifier to regular-expression matching is a GNU 'sed'\nextension which directs GNU 'sed' to match the regular expression\nin 'multi-line' mode.  The modifier causes '^' and '$' to match\nrespectively (in addition to the normal behavior) the empty string\nafter a newline, and the empty string before a newline.  There are\nspecial character sequences ('\\`' and '\\'') which always match the\nbeginning or the end of the buffer.  In addition, the period\ncharacter does not match a new-line character in multi-line mode.\n\n---------- Footnotes ----------\n\n(1) This is equivalent to 'p' unless the '-i' option is being used.\n\nFile: sed.info,  Node: Common Commands,  Next: Other Commands,  Prev: The \"s\" Command,  Up: sed scripts\n"
                },
                {
                    "name": "3.4 Often-Used Commands",
                    "content": "If you use 'sed' at all, you will quite likely want to know these\ncommands.\n\n'#'\n[No addresses allowed.]\n\nThe '#' character begins a comment; the comment continues until the\nnext newline.\n\nIf you are concerned about portability, be aware that some\nimplementations of 'sed' (which are not POSIX conforming) may only\nsupport a single one-line comment, and then only when the very\nfirst character of the script is a '#'.\n\nWarning: if the first two characters of the 'sed' script are '#n',\nthen the '-n' (no-autoprint) option is forced.  If you want to put\na comment in the first line of your script and that comment begins\nwith the letter 'n' and you do not want this behavior, then be sure\nto either use a capital 'N', or place at least one space before the\n'n'.\n\n'q [EXIT-CODE]'\nExit 'sed' without processing any more commands or input.\n\nExample: stop after printing the second line:\n$ seq 3 | sed 2q\n1\n2\n\nThis command accepts only one address.  Note that the current\npattern space is printed if auto-print is not disabled with the\n'-n' options.  The ability to return an exit code from the 'sed'\nscript is a GNU 'sed' extension.\n\nSee also the GNU 'sed' extension 'Q' command which quits silently\nwithout printing the current pattern space.\n\n'd'\nDelete the pattern space; immediately start next cycle.\n\nExample: delete the second input line:\n$ seq 3 | sed 2d\n1\n3\n\n'p'\nPrint out the pattern space (to the standard output).  This command\nis usually only used in conjunction with the '-n' command-line\noption.\n\nExample: print only the second input line:\n$ seq 3 | sed -n 2p\n2\n\n'n'\nIf auto-print is not disabled, print the pattern space, then,\nregardless, replace the pattern space with the next line of input.\nIf there is no more input then 'sed' exits without processing any\nmore commands.\n\nThis command is useful to skip lines (e.g.  process every Nth\nline).\n\nExample: perform substitution on every 3rd line (i.e.  two 'n'\ncommands skip two lines):\n$ seq 6 | sed 'n;n;s/./x/'\n1\n2\nx\n4\n5\nx\n\nGNU 'sed' provides an extension address syntax of FIRST~STEP to\nachieve the same result:\n\n$ seq 6 | sed '0~3s/./x/'\n1\n2\nx\n4\n5\nx\n\n'{ COMMANDS }'\nA group of commands may be enclosed between '{' and '}' characters.\nThis is particularly useful when you want a group of commands to be\ntriggered by a single address (or address-range) match.\n\nExample: perform substitution then print the second input line:\n$ seq 3 | sed -n '2{s/2/X/ ; p}'\nX\n\nFile: sed.info,  Node: Other Commands,  Next: Programming Commands,  Prev: Common Commands,  Up: sed scripts\n"
                },
                {
                    "name": "3.5 Less Frequently-Used Commands",
                    "content": "Though perhaps less frequently used than those in the previous section,\nsome very small yet useful 'sed' scripts can be built with these\ncommands.\n\n'y/SOURCE-CHARS/DEST-CHARS/'\nTransliterate any characters in the pattern space which match any\nof the SOURCE-CHARS with the corresponding character in DEST-CHARS.\n\nExample: transliterate 'a-j' into '0-9':\n$ echo hello world | sed 'y/abcdefghij/0123456789/'\n74llo worl3\n\n(The '/' characters may be uniformly replaced by any other single\ncharacter within any given 'y' command.)\n\nInstances of the '/' (or whatever other character is used in its\nstead), '\\', or newlines can appear in the SOURCE-CHARS or\nDEST-CHARS lists, provide that each instance is escaped by a '\\'.\nThe SOURCE-CHARS and DEST-CHARS lists must contain the same\nnumber of characters (after de-escaping).\n\nSee the 'tr' command from GNU coreutils for similar functionality.\n\n'a TEXT'\nAppending TEXT after a line.  This is a GNU extension to the\nstandard 'a' command - see below for details.\n\nExample: Add the word 'hello' after the second line:\n$ seq 3 | sed '2a hello'\n1\n2\nhello\n3\n\nLeading whitespace after the 'a' command is ignored.  The text to\nadd is read until the end of the line.\n\n'a\\'\n'TEXT'\nAppending TEXT after a line.\n\nExample: Add 'hello' after the second line (-| indicates printed\noutput lines):\n$ seq 3 | sed '2a\\\nhello'\n-|1\n-|2\n-|hello\n-|3\n\nThe 'a' command queues the lines of text which follow this command\n(each but the last ending with a '\\', which are removed from the\noutput) to be output at the end of the current cycle, or when the\nnext input line is read.\n\nAs a GNU extension, this command accepts two addresses.\n\nEscape sequences in TEXT are processed, so you should use '\\\\' in\nTEXT to print a single backslash.\n\nThe commands resume after the last line without a backslash ('\\') -\n'world' in the following example:\n$ seq 3 | sed '2a\\\nhello\\\nworld\n3s/./X/'\n-|1\n-|2\n-|hello\n-|world\n-|X\n\nAs a GNU extension, the 'a' command and TEXT can be separated into\ntwo '-e' parameters, enabling easier scripting:\n$ seq 3 | sed -e '2a\\' -e hello\n1\n2\nhello\n3\n\n$ sed -e '2a\\' -e \"$VAR\"\n\n'i TEXT'\ninsert TEXT before a line.  This is a GNU extension to the standard\n'i' command - see below for details.\n\nExample: Insert the word 'hello' before the second line:\n$ seq 3 | sed '2i hello'\n1\nhello\n2\n3\n\nLeading whitespace after the 'i' command is ignored.  The text to\nadd is read until the end of the line.\n\n'i\\'\n'TEXT'\nImmediately output the lines of text which follow this command.\n\nExample: Insert 'hello' before the second line (-| indicates\nprinted output lines):\n$ seq 3 | sed '2i\\\nhello'\n-|1\n-|hello\n-|2\n-|3\n\nAs a GNU extension, this command accepts two addresses.\n\nEscape sequences in TEXT are processed, so you should use '\\\\' in\nTEXT to print a single backslash.\n\nThe commands resume after the last line without a backslash ('\\') -\n'world' in the following example:\n$ seq 3 | sed '2i\\\nhello\\\nworld\ns/./X/'\n-|X\n-|hello\n-|world\n-|X\n-|X\n\nAs a GNU extension, the 'i' command and TEXT can be separated into\ntwo '-e' parameters, enabling easier scripting:\n$ seq 3 | sed -e '2i\\' -e hello\n1\nhello\n2\n3\n\n$ sed -e '2i\\' -e \"$VAR\"\n\n'c TEXT'\nReplaces the line(s) with TEXT.  This is a GNU extension to the\nstandard 'c' command - see below for details.\n\nExample: Replace the 2nd to 9th lines with the word 'hello':\n$ seq 10 | sed '2,9c hello'\n1\nhello\n10\n\nLeading whitespace after the 'c' command is ignored.  The text to\nadd is read until the end of the line.\n\n'c\\'\n'TEXT'\nDelete the lines matching the address or address-range, and output\nthe lines of text which follow this command.\n\nExample: Replace 2nd to 4th lines with the words 'hello' and\n'world' (-| indicates printed output lines):\n$ seq 5 | sed '2,4c\\\nhello\\\nworld'\n-|1\n-|hello\n-|world\n-|5\n\nIf no addresses are given, each line is replaced.\n\nA new cycle is started after this command is done, since the\npattern space will have been deleted.  In the following example,\nthe 'c' starts a new cycle and the substitution command is not\nperformed on the replaced text:\n\n$ seq 3 | sed '2c\\\nhello\ns/./X/'\n-|X\n-|hello\n-|X\n\nAs a GNU extension, the 'c' command and TEXT can be separated into\ntwo '-e' parameters, enabling easier scripting:\n$ seq 3 | sed -e '2c\\' -e hello\n1\nhello\n3\n\n$ sed -e '2c\\' -e \"$VAR\"\n\n'='\nPrint out the current input line number (with a trailing newline).\n\n$ printf '%s\\n' aaa bbb ccc | sed =\n1\naaa\n2\nbbb\n3\nccc\n\nAs a GNU extension, this command accepts two addresses.\n\n'l N'\nPrint the pattern space in an unambiguous form: non-printable\ncharacters (and the '\\' character) are printed in C-style escaped\nform; long lines are split, with a trailing '\\' character to\nindicate the split; the end of each line is marked with a '$'.\n\nN specifies the desired line-wrap length; a length of 0 (zero)\nmeans to never wrap long lines.  If omitted, the default as\nspecified on the command line is used.  The N parameter is a GNU\n'sed' extension.\n\n'r FILENAME'\n\nReads file FILENAME.  Example:\n\n$ seq 3 | sed '2r/etc/hostname'\n1\n2\nfencepost.gnu.org\n3\n\nQueue the contents of FILENAME to be read and inserted into the\noutput stream at the end of the current cycle, or when the next\ninput line is read.  Note that if FILENAME cannot be read, it is\ntreated as if it were an empty file, without any error indication.\n\nAs a GNU 'sed' extension, the special value '/dev/stdin' is\nsupported for the file name, which reads the contents of the\nstandard input.\n\nAs a GNU extension, this command accepts two addresses.  The file\nwill then be reread and inserted on each of the addressed lines.\n\n'w FILENAME'\nWrite the pattern space to FILENAME.  As a GNU 'sed' extension, two\nspecial values of FILENAME are supported: '/dev/stderr', which\nwrites the result to the standard error, and '/dev/stdout', which\nwrites to the standard output.(1)\n\nThe file will be created (or truncated) before the first input line\nis read; all 'w' commands (including instances of the 'w' flag on\nsuccessful 's' commands) which refer to the same FILENAME are\noutput without closing and reopening the file.\n\n'D'\nIf pattern space contains no newline, start a normal new cycle as\nif the 'd' command was issued.  Otherwise, delete text in the\npattern space up to the first newline, and restart cycle with the\nresultant pattern space, without reading a new line of input.\n\n'N'\nAdd a newline to the pattern space, then append the next line of\ninput to the pattern space.  If there is no more input then 'sed'\nexits without processing any more commands.\n\nWhen '-z' is used, a zero byte (the ascii 'NUL' character) is added\nbetween the lines (instead of a new line).\n\nBy default 'sed' does not terminate if there is no 'next' input\nline.  This is a GNU extension which can be disabled with\n'--posix'.  *Note N command on the last line: Ncommandlastline.\n\n'P'\nPrint out the portion of the pattern space up to the first newline.\n\n'h'\nReplace the contents of the hold space with the contents of the\npattern space.\n\n'H'\nAppend a newline to the contents of the hold space, and then append\nthe contents of the pattern space to that of the hold space.\n\n'g'\nReplace the contents of the pattern space with the contents of the\nhold space.\n\n'G'\nAppend a newline to the contents of the pattern space, and then\nappend the contents of the hold space to that of the pattern space.\n\n'x'\nExchange the contents of the hold and pattern spaces.\n\n---------- Footnotes ----------\n\n(1) This is equivalent to 'p' unless the '-i' option is being used.\n\nFile: sed.info,  Node: Programming Commands,  Next: Extended Commands,  Prev: Other Commands,  Up: sed scripts\n"
                },
                {
                    "name": "3.6 Commands for 'sed' gurus",
                    "content": "In most cases, use of these commands indicates that you are probably\nbetter off programming in something like 'awk' or Perl.  But\noccasionally one is committed to sticking with 'sed', and these commands\ncan enable one to write quite convoluted scripts.\n\n': LABEL'\n[No addresses allowed.]\n\nSpecify the location of LABEL for branch commands.  In all other\nrespects, a no-op.\n\n'b LABEL'\nUnconditionally branch to LABEL.  The LABEL may be omitted, in\nwhich case the next cycle is started.\n\n't LABEL'\nBranch to LABEL only if there has been a successful 's'ubstitution\nsince the last input line was read or conditional branch was taken.\nThe LABEL may be omitted, in which case the next cycle is started.\n\nFile: sed.info,  Node: Extended Commands,  Next: Multiple commands syntax,  Prev: Programming Commands,  Up: sed scripts\n"
                },
                {
                    "name": "3.7 Commands Specific to GNU 'sed'",
                    "content": "These commands are specific to GNU 'sed', so you must use them with care\nand only when you are sure that hindering portability is not evil.  They\nallow you to check for GNU 'sed' extensions or to do tasks that are\nrequired quite often, yet are unsupported by standard 'sed's.\n\n'e [COMMAND]'\nThis command allows one to pipe input from a shell command into\npattern space.  Without parameters, the 'e' command executes the\ncommand that is found in pattern space and replaces the pattern\nspace with the output; a trailing newline is suppressed.\n\nIf a parameter is specified, instead, the 'e' command interprets it\nas a command and sends its output to the output stream.  The\ncommand can run across multiple lines, all but the last ending with\na back-slash.\n\nIn both cases, the results are undefined if the command to be\nexecuted contains a NUL character.\n\nNote that, unlike the 'r' command, the output of the command will\nbe printed immediately; the 'r' command instead delays the output\nto the end of the current cycle.\n\n'F'\nPrint out the file name of the current input file (with a trailing\nnewline).\n\n'Q [EXIT-CODE]'\nThis command accepts only one address.\n\nThis command is the same as 'q', but will not print the contents of\npattern space.  Like 'q', it provides the ability to return an exit\ncode to the caller.\n\nThis command can be useful because the only alternative ways to\naccomplish this apparently trivial function are to use the '-n'\noption (which can unnecessarily complicate your script) or\nresorting to the following snippet, which wastes time by reading\nthe whole file without any visible effect:\n\n:eat\n$d       Quit silently on the last line\nN        Read another line, silently\ng        Overwrite pattern space each time to save memory\nb eat\n\n'R FILENAME'\nQueue a line of FILENAME to be read and inserted into the output\nstream at the end of the current cycle, or when the next input line\nis read.  Note that if FILENAME cannot be read, or if its end is\nreached, no line is appended, without any error indication.\n\nAs with the 'r' command, the special value '/dev/stdin' is\nsupported for the file name, which reads a line from the standard\ninput.\n\n'T LABEL'\nBranch to LABEL only if there have been no successful\n's'ubstitutions since the last input line was read or conditional\nbranch was taken.  The LABEL may be omitted, in which case the next\ncycle is started.\n\n'v VERSION'\nThis command does nothing, but makes 'sed' fail if GNU 'sed'\nextensions are not supported, simply because other versions of\n'sed' do not implement it.  In addition, you can specify the\nversion of 'sed' that your script requires, such as '4.0.5'.  The\ndefault is '4.0' because that is the first version that implemented\nthis command.\n\nThis command enables all GNU extensions even if 'POSIXLYCORRECT'\nis set in the environment.\n\n'W FILENAME'\nWrite to the given filename the portion of the pattern space up to\nthe first newline.  Everything said under the 'w' command about\nfile handling holds here too.\n\n'z'\nThis command empties the content of pattern space.  It is usually\nthe same as 's/.*//', but is more efficient and works in the\npresence of invalid multibyte sequences in the input stream.  POSIX\nmandates that such sequences are not matched by '.', so that\nthere is no portable way to clear 'sed''s buffers in the middle of\nthe script in most multibyte locales (including UTF-8 locales).\n\nFile: sed.info,  Node: Multiple commands syntax,  Prev: Extended Commands,  Up: sed scripts\n"
                },
                {
                    "name": "3.8 Multiple commands syntax",
                    "content": "There are several methods to specify multiple commands in a 'sed'\nprogram.\n\nUsing newlines is most natural when running a sed script from a file\n(using the '-f' option).\n\nOn the command line, all 'sed' commands may be separated by newlines.\nAlternatively, you may specify each command as an argument to an '-e'\noption:\n\n$ seq 6 | sed '1d\n3d\n5d'\n2\n4\n6\n\n$ seq 6 | sed -e 1d -e 3d -e 5d\n2\n4\n6\n\nA semicolon (';') may be used to separate most simple commands:\n\n$ seq 6 | sed '1d;3d;5d'\n2\n4\n6\n\nThe '{','}','b','t','T',':' commands can be separated with a\nsemicolon (this is a non-portable GNU 'sed' extension).\n\n$ seq 4 | sed '{1d;3d}'\n2\n4\n\n$ seq 6 | sed '{1d;3d};5d'\n2\n4\n6\n\nLabels used in 'b','t','T',':' commands are read until a semicolon.\nLeading and trailing whitespace is ignored.  In the examples below the\nlabel is 'x'.  The first example works with GNU 'sed'.  The second is a\nportable equivalent.  For more information about branching and labels\n*note Branching and flow control::.\n\n$ seq 3 | sed '/1/b x ; s/^/=/ ; :x ; 3d'\n1\n=2\n\n$ seq 3 | sed -e '/1/bx' -e 's/^/=/' -e ':x' -e '3d'\n1\n=2\n\n\nThe following commands cannot be separated by a semicolon and require a\nnewline:\n\n'a','c','i' (append/change/insert)\n\nAll characters following 'a','c','i' commands are taken as the text\nto append/change/insert.  Using a semicolon leads to undesirable\nresults:\n\n$ seq 2 | sed '1aHello ; 2d'\n1\nHello ; 2d\n2\n\nSeparate the commands using '-e' or a newline:\n\n$ seq 2 | sed -e 1aHello -e 2d\n1\nHello\n\n$ seq 2 | sed '1aHello\n2d'\n1\nHello\n\nNote that specifying the text to add ('Hello') immediately after\n'a','c','i' is itself a GNU 'sed' extension.  A portable,\nPOSIX-compliant alternative is:\n\n$ seq 2 | sed '1a\\\nHello\n2d'\n1\nHello\n\n'#' (comment)\n\nAll characters following '#' until the next newline are ignored.\n\n$ seq 3 | sed '# this is a comment ; 2d'\n1\n2\n3\n\n\n$ seq 3 | sed '# this is a comment\n2d'\n1\n3\n\n'r','R','w','W' (reading and writing files)\n\nThe 'r','R','w','W' commands parse the filename until end of the\nline.  If whitespace, comments or semicolons are found, they will\nbe included in the filename, leading to unexpected results:\n\n$ seq 2 | sed '1w hello.txt ; 2d'\n1\n2\n\n$ ls -log\ntotal 4\n-rw-rw-r-- 1 2 Jan 23 23:03 hello.txt ; 2d\n\n$ cat 'hello.txt ; 2d'\n1\n\nNote that 'sed' silently ignores read/write errors in\n'r','R','w','W' commands (such as missing files).  In the following\nexample, 'sed' tries to read a file named ''hello.txt ; N''.  The\nfile is missing, and the error is silently ignored:\n\n$ echo x | sed '1rhello.txt ; N'\nx\n\n'e' (command execution)\n\nAny characters following the 'e' command until the end of the line\nwill be sent to the shell.  If whitespace, comments or semicolons\nare found, they will be included in the shell command, leading to\nunexpected results:\n\n$ echo a | sed '1e touch foo#bar'\na\n\n$ ls -1\nfoo#bar\n\n$ echo a | sed '1e touch foo ; s/a/b/'\nsh: 1: s/a/b/: not found\na\n\n's///[we]' (substitute with 'e' or 'w' flags)\n\nIn a substitution command, the 'w' flag writes the substitution\nresult to a file, and the 'e' flag executes the subsitution result\nas a shell command.  As with the 'r/R/w/W/e' commands, these must\nbe terminated with a newline.  If whitespace, comments or\nsemicolons are found, they will be included in the shell command or\nfilename, leading to unexpected results:\n\n$ echo a | sed 's/a/b/w1.txt#foo'\nb\n\n$ ls -1\n1.txt#foo\n\nFile: sed.info,  Node: sed addresses,  Next: sed regular expressions,  Prev: sed scripts,  Up: Top\n"
                }
            ]
        },
        "4 Addresses: selecting lines": {
            "content": "* Menu:\n\n* Addresses overview::                Addresses overview\n* Numeric Addresses::                 selecting lines by numbers\n* Regexp Addresses::                  selecting lines by text matching\n* Range Addresses::                   selecting a range of lines\n\nFile: sed.info,  Node: Addresses overview,  Next: Numeric Addresses,  Up: sed addresses\n",
            "subsections": [
                {
                    "name": "4.1 Addresses overview",
                    "content": "Addresses determine on which line(s) the 'sed' command will be executed.\nThe following command replaces the word 'hello' with 'world' only on\nline 144:\n\nsed '144s/hello/world/' input.txt > output.txt\n\nIf no addresses are given, the command is performed on all lines.\nThe following command replaces the word 'hello' with 'world' on all\nlines in the input file:\n\nsed 's/hello/world/' input.txt > output.txt\n\nAddresses can contain regular expressions to match lines based on\ncontent instead of line numbers.  The following command replaces the\nword 'hello' with 'world' only in lines containing the word 'apple':\n\nsed '/apple/s/hello/world/' input.txt > output.txt\n\nAn address range is specified with two addresses separated by a comma\n(',').  Addresses can be numeric, regular expressions, or a mix of both.\nThe following command replaces the word 'hello' with 'world' only in\nlines 4 to 17 (inclusive):\n\nsed '4,17s/hello/world/' input.txt > output.txt\n\nAppending the '!' character to the end of an address specification\n(before the command letter) negates the sense of the match.  That is, if\nthe '!' character follows an address or an address range, then only\nlines which do not match the addresses will be selected.  The\nfollowing command replaces the word 'hello' with 'world' only in lines\nnot containing the word 'apple':\n\nsed '/apple/!s/hello/world/' input.txt > output.txt\n\nThe following command replaces the word 'hello' with 'world' only in\nlines 1 to 3 and 18 till the last line of the input file (i.e.\nexcluding lines 4 to 17):\n\nsed '4,17!s/hello/world/' input.txt > output.txt\n\nFile: sed.info,  Node: Numeric Addresses,  Next: Regexp Addresses,  Prev: Addresses overview,  Up: sed addresses\n"
                },
                {
                    "name": "4.2 Selecting lines by numbers",
                    "content": "Addresses in a 'sed' script can be in any of the following forms:\n'NUMBER'\nSpecifying a line number will match only that line in the input.\n(Note that 'sed' counts lines continuously across all input files\nunless '-i' or '-s' options are specified.)\n\n'$'\nThis address matches the last line of the last file of input, or\nthe last line of each file when the '-i' or '-s' options are\nspecified.\n\n'FIRST~STEP'\nThis GNU extension matches every STEPth line starting with line\nFIRST.  In particular, lines will be selected when there exists a\nnon-negative N such that the current line-number equals FIRST + (N\n* STEP).  Thus, one would use '1~2' to select the odd-numbered\nlines and '0~2' for even-numbered lines; to pick every third line\nstarting with the second, '2~3' would be used; to pick every fifth\nline starting with the tenth, use '10~5'; and '50~0' is just an\nobscure way of saying '50'.\n\nThe following commands demonstrate the step address usage:\n\n$ seq 10 | sed -n '0~4p'\n4\n8\n\n$ seq 10 | sed -n '1~3p'\n1\n4\n7\n10\n\nFile: sed.info,  Node: Regexp Addresses,  Next: Range Addresses,  Prev: Numeric Addresses,  Up: sed addresses\n"
                },
                {
                    "name": "4.3 selecting lines by text matching",
                    "content": "GNU 'sed' supports the following regular expression addresses.  The\ndefault regular expression is *note Basic Regular Expression (BRE): BRE\nsyntax.  If '-E' or '-r' options are used, The regular expression should\nbe in *note Extended Regular Expression (ERE): ERE syntax. syntax.\n*Note BRE vs ERE::.\n\n'/REGEXP/'\nThis will select any line which matches the regular expression\nREGEXP.  If REGEXP itself includes any '/' characters, each must be\nescaped by a backslash ('\\').\n\nThe following command prints lines in '/etc/passwd' which end with\n'bash'(1):\n\nsed -n '/bash$/p' /etc/passwd\n\nThe empty regular expression '//' repeats the last regular\nexpression match (the same holds if the empty regular expression is\npassed to the 's' command).  Note that modifiers to regular\nexpressions are evaluated when the regular expression is compiled,\nthus it is invalid to specify them together with the empty regular\nexpression.\n\n'\\%REGEXP%'\n(The '%' may be replaced by any other single character.)\n\nThis also matches the regular expression REGEXP, but allows one to\nuse a different delimiter than '/'.  This is particularly useful if\nthe REGEXP itself contains a lot of slashes, since it avoids the\ntedious escaping of every '/'.  If REGEXP itself includes any\ndelimiter characters, each must be escaped by a backslash ('\\').\n\nThe following commands are equivalent.  They print lines which\nstart with '/home/alice/documents/':\n\nsed -n '/^\\/home\\/alice\\/documents\\//p'\nsed -n '\\%^/home/alice/documents/%p'\nsed -n '\\;^/home/alice/documents/;p'\n\n'/REGEXP/I'\n'\\%REGEXP%I'\nThe 'I' modifier to regular-expression matching is a GNU extension\nwhich causes the REGEXP to be matched in a case-insensitive manner.\n\nIn many other programming languages, a lower case 'i' is used for\ncase-insensitive regular expression matching.  However, in 'sed'\nthe 'i' is used for the insert command (*note insert command::).\n\nObserve the difference between the following examples.\n\nIn this example, '/b/I' is the address: regular expression with 'I'\nmodifier.  'd' is the delete command:\n\n$ printf \"%s\\n\" a b c | sed '/b/Id'\na\nc\n\nHere, '/b/' is the address: a regular expression.  'i' is the\ninsert command.  'd' is the value to insert.  A line with 'd' is\nthen inserted above the matched line:\n\n$ printf \"%s\\n\" a b c | sed '/b/id'\na\nd\nb\nc\n\n'/REGEXP/M'\n'\\%REGEXP%M'\nThe 'M' modifier to regular-expression matching is a GNU 'sed'\nextension which directs GNU 'sed' to match the regular expression\nin 'multi-line' mode.  The modifier causes '^' and '$' to match\nrespectively (in addition to the normal behavior) the empty string\nafter a newline, and the empty string before a newline.  There are\nspecial character sequences ('\\`' and '\\'') which always match the\nbeginning or the end of the buffer.  In addition, the period\ncharacter does not match a new-line character in multi-line mode.\n\nRegex addresses operate on the content of the current pattern space.\nIf the pattern space is changed (for example with 's///' command) the\nregular expression matching will operate on the changed text.\n\nIn the following example, automatic printing is disabled with '-n'.\nThe 's/2/X/' command changes lines containing '2' to 'X'.  The command\n'/[0-9]/p' matches lines with digits and prints them.  Because the\nsecond line is changed before the '/[0-9]/' regex, it will not match and\nwill not be printed:\n\n$ seq 3 | sed -n 's/2/X/ ; /[0-9]/p'\n1\n3\n\n---------- Footnotes ----------\n\n(1) There are of course many other ways to do the same, e.g.\ngrep 'bash$' /etc/passwd\nawk -F: '$7 == \"/bin/bash\"' /etc/passwd\n\nFile: sed.info,  Node: Range Addresses,  Prev: Regexp Addresses,  Up: sed addresses\n"
                },
                {
                    "name": "4.4 Range Addresses",
                    "content": "An address range can be specified by specifying two addresses separated\nby a comma (',').  An address range matches lines starting from where\nthe first address matches, and continues until the second address\nmatches (inclusively):\n\n$ seq 10 | sed -n '4,6p'\n4\n5\n6\n\nIf the second address is a REGEXP, then checking for the ending match\nwill start with the line following the line which matched the first\naddress: a range will always span at least two lines (except of course\nif the input stream ends).\n\n$ seq 10 | sed -n '4,/[0-9]/p'\n4\n5\n\nIf the second address is a NUMBER less than (or equal to) the line\nmatching the first address, then only the one line is matched:\n\n$ seq 10 | sed -n '4,1p'\n4\n\nGNU 'sed' also supports some special two-address forms; all these are\nGNU extensions:\n'0,/REGEXP/'\nA line number of '0' can be used in an address specification like\n'0,/REGEXP/' so that 'sed' will try to match REGEXP in the first\ninput line too.  In other words, '0,/REGEXP/' is similar to\n'1,/REGEXP/', except that if ADDR2 matches the very first line of\ninput the '0,/REGEXP/' form will consider it to end the range,\nwhereas the '1,/REGEXP/' form will match the beginning of its range\nand hence make the range span up to the second occurrence of the\nregular expression.\n\nNote that this is the only place where the '0' address makes sense;\nthere is no 0-th line and commands which are given the '0' address\nin any other way will give an error.\n\nThe following examples demonstrate the difference between starting\nwith address 1 and 0:\n\n$ seq 10 | sed -n '1,/[0-9]/p'\n1\n2\n\n$ seq 10 | sed -n '0,/[0-9]/p'\n1\n\n'ADDR1,+N'\nMatches ADDR1 and the N lines following ADDR1.\n\n$ seq 10 | sed -n '6,+2p'\n6\n7\n8\n\nADDR1 can be a line number or a regular expression.\n\n'ADDR1,~N'\nMatches ADDR1 and the lines following ADDR1 until the next line\nwhose input line number is a multiple of N.  The following command\nprints starting at line 6, until the next line which is a multiple\nof 4 (i.e.  line 8):\n\n$ seq 10 | sed -n '6,~4p'\n6\n7\n8\n\nADDR1 can be a line number or a regular expression.\n\nFile: sed.info,  Node: sed regular expressions,  Next: advanced sed,  Prev: sed addresses,  Up: Top\n"
                }
            ]
        },
        "5 Regular Expressions: selecting text": {
            "content": "* Menu:\n\n* Regular Expressions Overview:: Overview of Regular expression in 'sed'\n* BRE vs ERE::               Basic (BRE) and extended (ERE) regular expression\nsyntax\n* BRE syntax::               Overview of basic regular expression syntax\n* ERE syntax::               Overview of extended regular expression syntax\n* Character Classes and Bracket Expressions::\n* regexp extensions::        Additional regular expression commands\n* Back-references and Subexpressions:: Back-references and Subexpressions\n* Escapes::                  Specifying special characters\n* Locale Considerations::    Multibyte characters and locale considrations\n\nFile: sed.info,  Node: Regular Expressions Overview,  Next: BRE vs ERE,  Up: sed regular expressions\n",
            "subsections": [
                {
                    "name": "5.1 Overview of regular expression in 'sed'",
                    "content": "To know how to use 'sed', people should understand regular expressions\n(\"regexp\" for short).  A regular expression is a pattern that is matched\nagainst a subject string from left to right.  Most characters are\n\"ordinary\": they stand for themselves in a pattern, and match the\ncorresponding characters.  Regular expressions in 'sed' are specified\nbetween two slashes.\n\nThe following command prints lines containing the word 'hello':\n\nsed -n '/hello/p'\n\nThe above example is equivalent to this 'grep' command:\n\ngrep 'hello'\n\nThe power of regular expressions comes from the ability to include\nalternatives and repetitions in the pattern.  These are encoded in the\npattern by the use of \"special characters\", which do not stand for\nthemselves but instead are interpreted in some special way.\n\nThe character '^' (caret) in a regular expression matches the\nbeginning of the line.  The character '.' (dot) matches any single\ncharacter.  The following 'sed' command matches and prints lines which\nstart with the letter 'b', followed by any single character, followed by\nthe letter 'd':\n\n$ printf \"%s\\n\" abode bad bed bit bid byte body | sed -n '/^b.d/p'\nbad\nbed\nbid\nbody\n\nThe following sections explain the meaning and usage of special\ncharacters in regular expressions.\n\nFile: sed.info,  Node: BRE vs ERE,  Next: BRE syntax,  Prev: Regular Expressions Overview,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.2 Basic (BRE) and extended (ERE) regular expression",
                    "content": "Basic and extended regular expressions are two variations on the syntax\nof the specified pattern.  Basic Regular Expression (BRE) syntax is the\ndefault in 'sed' (and similarly in 'grep').  Use the POSIX-specified\n'-E' option ('-r', '--regexp-extended') to enable Extended Regular\nExpression (ERE) syntax.\n\nIn GNU 'sed', the only difference between basic and extended regular\nexpressions is in the behavior of a few special characters: '?', '+',\nparentheses, braces ('{}'), and '|'.\n\nWith basic (BRE) syntax, these characters do not have special meaning\nunless prefixed with a backslash ('\\'); While with extended (ERE) syntax\nit is reversed: these characters are special unless they are prefixed\nwith backslash ('\\').\n\nDesired pattern      Basic (BRE) Syntax         Extended (ERE) Syntax\n\n--------------------------------------------------------------------------\nliteral '+' (plus         $ echo 'a+b=c' > foo       $ echo 'a+b=c' > foo\nsign)                     $ sed -n '/a+b/p' foo      $ sed -E -n '/a\\+b/p' foo\na+b=c                      a+b=c\n\nOne or more 'a'           $ echo aab > foo           $ echo aab > foo\ncharacters                $ sed -n '/a\\+b/p' foo     $ sed -E -n '/a+b/p' foo\nfollowed by 'b'           aab                        aab\n(plus sign as\nspecial\nmeta-character)\n\nFile: sed.info,  Node: BRE syntax,  Next: ERE syntax,  Prev: BRE vs ERE,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.3 Overview of basic regular expression syntax",
                    "content": "Here is a brief description of regular expression syntax as used in\n'sed'.\n\n'CHAR'\nA single ordinary character matches itself.\n\n'*'\nMatches a sequence of zero or more instances of matches for the\npreceding regular expression, which must be an ordinary character,\na special character preceded by '\\', a '.', a grouped regexp (see\nbelow), or a bracket expression.  As a GNU extension, a postfixed\nregular expression can also be followed by '*'; for example, 'a'\nis equivalent to 'a*'.  POSIX 1003.1-2001 says that '*' stands for\nitself when it appears at the start of a regular expression or\nsubexpression, but many nonGNU implementations do not support this\nand portable scripts should instead use '\\*' in these contexts.\n'.'\nMatches any character, including newline.\n\n'^'\nMatches the null string at beginning of the pattern space, i.e.\nwhat appears after the circumflex must appear at the beginning of\nthe pattern space.\n\nIn most scripts, pattern space is initialized to the content of\neach line (*note How 'sed' works: Execution Cycle.).  So, it is a\nuseful simplification to think of '^#include' as matching only\nlines where '#include' is the first thing on line--if there are\nspaces before, for example, the match fails.  This simplification\nis valid as long as the original content of pattern space is not\nmodified, for example with an 's' command.\n\n'^' acts as a special character only at the beginning of the\nregular expression or subexpression (that is, after '\\(' or '\\|').\nPortable scripts should avoid '^' at the beginning of a\nsubexpression, though, as POSIX allows implementations that treat\n'^' as an ordinary character in that context.\n\n'$'\nIt is the same as '^', but refers to end of pattern space.  '$'\nalso acts as a special character only at the end of the regular\nexpression or subexpression (that is, before '\\)' or '\\|'), and its\nuse at the end of a subexpression is not portable.\n\n'[LIST]'\n'[^LIST]'\nMatches any single character in LIST: for example, '[aeiou]'\nmatches all vowels.  A list may include sequences like\n'CHAR1-CHAR2', which matches any character between (inclusive)\nCHAR1 and CHAR2.  *Note Character Classes and Bracket\nExpressions::.\n\n'\\+'\nAs '*', but matches one or more.  It is a GNU extension.\n\n'\\?'\nAs '*', but only matches zero or one.  It is a GNU extension.\n\n'\\{I\\}'\nAs '*', but matches exactly I sequences (I is a decimal integer;\nfor portability, keep it between 0 and 255 inclusive).\n\n'\\{I,J\\}'\nMatches between I and J, inclusive, sequences.\n\n'\\{I,\\}'\nMatches more than or equal to I sequences.\n\n'\\(REGEXP\\)'\nGroups the inner REGEXP as a whole, this is used to:\n\n* Apply postfix operators, like '\\(abcd\\)*': this will search\nfor zero or more whole sequences of 'abcd', while 'abcd*'\nwould search for 'abc' followed by zero or more occurrences of\n'd'.  Note that support for '\\(abcd\\)*' is required by POSIX\n1003.1-2001, but many non-GNU implementations do not support\nit and hence it is not universally portable.\n\n* Use back references (see below).\n\n'REGEXP1\\|REGEXP2'\nMatches either REGEXP1 or REGEXP2.  Use parentheses to use complex\nalternative regular expressions.  The matching process tries each\nalternative in turn, from left to right, and the first one that\nsucceeds is used.  It is a GNU extension.\n\n'REGEXP1REGEXP2'\nMatches the concatenation of REGEXP1 and REGEXP2.  Concatenation\nbinds more tightly than '\\|', '^', and '$', but less tightly than\nthe other regular expression operators.\n\n'\\DIGIT'\nMatches the DIGIT-th '\\(...\\)' parenthesized subexpression in the\nregular expression.  This is called a \"back reference\".\nSubexpressions are implicitly numbered by counting occurrences of\n'\\(' left-to-right.\n\n'\\n'\nMatches the newline character.\n\n'\\CHAR'\nMatches CHAR, where CHAR is one of '$', '*', '.', '[', '\\', or '^'.\nNote that the only C-like backslash sequences that you can portably\nassume to be interpreted are '\\n' and '\\\\'; in particular '\\t' is\nnot portable, and matches a 't' under most implementations of\n'sed', rather than a tab character.\n\nNote that the regular expression matcher is greedy, i.e., matches are\nattempted from left to right and, if two or more matches are possible\nstarting at the same character, it selects the longest.\n\nExamples:\n'abcdef'\nMatches 'abcdef'.\n\n'a*b'\nMatches zero or more 'a's followed by a single 'b'.  For example,\n'b' or 'aaaaab'.\n\n'a\\?b'\nMatches 'b' or 'ab'.\n\n'a\\+b\\+'\nMatches one or more 'a's followed by one or more 'b's: 'ab' is the\nshortest possible match, but other examples are 'aaaab' or 'abbbbb'\nor 'aaaaaabbbbbbb'.\n\n'.*'\n'.\\+'\nThese two both match all the characters in a string; however, the\nfirst matches every string (including the empty string), while the\nsecond matches only strings containing at least one character.\n\n'^main.*(.*)'\nThis matches a string starting with 'main', followed by an opening\nand closing parenthesis.  The 'n', '(' and ')' need not be\nadjacent.\n\n'^#'\nThis matches a string beginning with '#'.\n\n'\\\\$'\nThis matches a string ending with a single backslash.  The regexp\ncontains two backslashes for escaping.\n\n'\\$'\nInstead, this matches a string consisting of a single dollar sign,\nbecause it is escaped.\n\n'[a-zA-Z0-9]'\nIn the C locale, this matches any ASCII letters or digits.\n\n'[^ '<TAB>']\\+'\n(Here '<TAB>' stands for a single tab character.)  This matches a\nstring of one or more characters, none of which is a space or a\ntab.  Usually this means a word.\n\n'^\\(.*\\)\\n\\1$'\nThis matches a string consisting of two equal substrings separated\nby a newline.\n\n'.\\{9\\}A$'\nThis matches nine characters followed by an 'A' at the end of a\nline.\n\n'^.\\{15\\}A'\nThis matches the start of a string that contains 16 characters, the\nlast of which is an 'A'.\n\nFile: sed.info,  Node: ERE syntax,  Next: Character Classes and Bracket Expressions,  Prev: BRE syntax,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.4 Overview of extended regular expression syntax",
                    "content": "The only difference between basic and extended regular expressions is in\nthe behavior of a few characters: '?', '+', parentheses, braces ('{}'),\nand '|'.  While basic regular expressions require these to be escaped if\nyou want them to behave as special characters, when using extended\nregular expressions you must escape them if you want them to match a\nliteral character.  '|' is special here because '\\|' is a GNU extension\n- standard basic regular expressions do not provide its functionality.\n\nExamples:\n'abc?'\nbecomes 'abc\\?' when using extended regular expressions.  It\nmatches the literal string 'abc?'.\n\n'c\\+'\nbecomes 'c+' when using extended regular expressions.  It matches\none or more 'c's.\n\n'a\\{3,\\}'\nbecomes 'a{3,}' when using extended regular expressions.  It\nmatches three or more 'a's.\n\n'\\(abc\\)\\{2,3\\}'\nbecomes '(abc){2,3}' when using extended regular expressions.  It\nmatches either 'abcabc' or 'abcabcabc'.\n\n'\\(abc*\\)\\1'\nbecomes '(abc*)\\1' when using extended regular expressions.\nBackreferences must still be escaped when using extended regular\nexpressions.\n\n'a\\|b'\nbecomes 'a|b' when using extended regular expressions.  It matches\n'a' or 'b'.\n\nFile: sed.info,  Node: Character Classes and Bracket Expressions,  Next: regexp extensions,  Prev: ERE syntax,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.5 Character Classes and Bracket Expressions",
                    "content": "A \"bracket expression\" is a list of characters enclosed by '[' and ']'.\nIt matches any single character in that list; if the first character of\nthe list is the caret '^', then it matches any character *not* in the\nlist.  For example, the following command replaces the words 'gray' or\n'grey' with 'blue':\n\nsed  's/gr[ae]y/blue/'\n\nBracket expressions can be used in both *note basic: BRE syntax. and\n*note extended: ERE syntax. regular expressions (that is, with or\nwithout the '-E'/'-r' options).\n\nWithin a bracket expression, a \"range expression\" consists of two\ncharacters separated by a hyphen.  It matches any single character that\nsorts between the two characters, inclusive.  In the default C locale,\nthe sorting sequence is the native character order; for example, '[a-d]'\nis equivalent to '[abcd]'.\n\nFinally, certain named classes of characters are predefined within\nbracket expressions, as follows.\n\nThese named classes must be used inside brackets themselves.\nCorrect usage:\n$ echo 1 | sed 's/[[:digit:]]/X/'\nX\n\nIncorrect usage is rejected by newer 'sed' versions.  Older versions\naccepted it but treated it as a single bracket expression (which is\nequivalent to '[dgit:]', that is, only the characters D/G/I/T/:):\n# current GNU sed versions - incorrect usage rejected\n$ echo 1 | sed 's/[:digit:]/X/'\nsed: character class syntax is [[:space:]], not [:space:]\n\n# older GNU sed versions\n$ echo 1 | sed 's/[:digit:]/X/'\n1\n\n'[:alnum:]'\nAlphanumeric characters: '[:alpha:]' and '[:digit:]'; in the 'C'\nlocale and ASCII character encoding, this is the same as\n'[0-9A-Za-z]'.\n\n'[:alpha:]'\nAlphabetic characters: '[:lower:]' and '[:upper:]'; in the 'C'\nlocale and ASCII character encoding, this is the same as\n'[A-Za-z]'.\n\n'[:blank:]'\nBlank characters: space and tab.\n\n'[:cntrl:]'\nControl characters.  In ASCII, these characters have octal codes\n000 through 037, and 177 (DEL). In other character sets, these are\nthe equivalent characters, if any.\n\n'[:digit:]'\nDigits: '0 1 2 3 4 5 6 7 8 9'.\n\n'[:graph:]'\nGraphical characters: '[:alnum:]' and '[:punct:]'.\n\n'[:lower:]'\nLower-case letters; in the 'C' locale and ASCII character encoding,\nthis is 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.\n\n'[:print:]'\nPrintable characters: '[:alnum:]', '[:punct:]', and space.\n\n'[:punct:]'\nPunctuation characters; in the 'C' locale and ASCII character\nencoding, this is '! \" # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \\\n] ^  ` { | } ~'.\n\n'[:space:]'\nSpace characters: in the 'C' locale, this is tab, newline, vertical\ntab, form feed, carriage return, and space.\n\n'[:upper:]'\nUpper-case letters: in the 'C' locale and ASCII character encoding,\nthis is 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'.\n\n'[:xdigit:]'\nHexadecimal digits: '0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f'.\n\nNote that the brackets in these class names are part of the symbolic\nnames, and must be included in addition to the brackets delimiting the\nbracket expression.\n\nMost meta-characters lose their special meaning inside bracket\nexpressions:\n\n']'\nends the bracket expression if it's not the first list item.  So,\nif you want to make the ']' character a list item, you must put it\nfirst.\n\n'-'\nrepresents the range if it's not first or last in a list or the\nending point of a range.\n\n'^'\nrepresents the characters not in the list.  If you want to make the\n'^' character a list item, place it anywhere but first.\n\nTODO: incorporate this paragraph (copied verbatim from BRE section).\n\nThe characters '$', '*', '.', '[', and '\\' are normally not special\nwithin LIST.  For example, '[\\*]' matches either '\\' or '*', because the\n'\\' is not special here.  However, strings like '[.ch.]', '[=a=]', and\n'[:space:]' are special within LIST and represent collating symbols,\nequivalence classes, and character classes, respectively, and '[' is\ntherefore special within LIST when it is followed by '.', '=', or ':'.\nAlso, when not in 'POSIXLYCORRECT' mode, special escapes like '\\n' and\n'\\t' are recognized within LIST.  *Note Escapes::.\n\n'[.'\nrepresents the open collating symbol.\n\n'.]'\nrepresents the close collating symbol.\n\n'[='\nrepresents the open equivalence class.\n\n'=]'\nrepresents the close equivalence class.\n\n'[:'\nrepresents the open character class symbol, and should be followed\nby a valid character class name.\n\n':]'\nrepresents the close character class symbol.\n\nFile: sed.info,  Node: regexp extensions,  Next: Back-references and Subexpressions,  Prev: Character Classes and Bracket Expressions,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.6 regular expression extensions",
                    "content": "The following sequences have special meaning inside regular expressions\n(used in *note addresses: Regexp Addresses. and the 's' command).\n\nThese can be used in both *note basic: BRE syntax. and *note\nextended: ERE syntax. regular expressions (that is, with or without the\n'-E'/'-r' options).\n\n'\\w'\nMatches any \"word\" character.  A \"word\" character is any letter or\ndigit or the underscore character.\n\n$ echo \"abc %-= def.\" | sed 's/\\w/X/g'\nXXX %-= XXX.\n\n'\\W'\nMatches any \"non-word\" character.\n\n$ echo \"abc %-= def.\" | sed 's/\\W/X/g'\nabcXXXXXdefX\n\n'\\b'\nMatches a word boundary; that is it matches if the character to the\nleft is a \"word\" character and the character to the right is a\n\"non-word\" character, or vice-versa.\n\n$ echo \"abc %-= def.\" | sed 's/\\b/X/g'\nXabcX %-= XdefX.\n\n'\\B'\nMatches everywhere but on a word boundary; that is it matches if\nthe character to the left and the character to the right are either\nboth \"word\" characters or both \"non-word\" characters.\n\n$ echo \"abc %-= def.\" | sed 's/\\B/X/g'\naXbXc X%X-X=X dXeXf.X\n\n'\\s'\nMatches whitespace characters (spaces and tabs).  Newlines embedded\nin the pattern/hold spaces will also match:\n\n$ echo \"abc %-= def.\" | sed 's/\\s/X/g'\nabcX%-=Xdef.\n\n'\\S'\nMatches non-whitespace characters.\n\n$ echo \"abc %-= def.\" | sed 's/\\S/X/g'\nXXX XXX XXXX\n\n'\\<'\nMatches the beginning of a word.\n\n$ echo \"abc %-= def.\" | sed 's/\\</X/g'\nXabc %-= Xdef.\n\n'\\>'\nMatches the end of a word.\n\n$ echo \"abc %-= def.\" | sed 's/\\>/X/g'\nabcX %-= defX.\n\n'\\`'\nMatches only at the start of pattern space.  This is different from\n'^' in multi-line mode.\n\nCompare the following two examples:\n\n$ printf \"a\\nb\\nc\\n\" | sed 'N;N;s/^/X/gm'\nXa\nXb\nXc\n\n$ printf \"a\\nb\\nc\\n\" | sed 'N;N;s/\\`/X/gm'\nXa\nb\nc\n\n'\\''\nMatches only at the end of pattern space.  This is different from\n'$' in multi-line mode.\n\nFile: sed.info,  Node: Back-references and Subexpressions,  Next: Escapes,  Prev: regexp extensions,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.7 Back-references and Subexpressions",
                    "content": "\"back-references\" are regular expression commands which refer to a\nprevious part of the matched regular expression.  Back-references are\nspecified with backslash and a single digit (e.g.  '\\1').  The part of\nthe regular expression they refer to is called a \"subexpression\", and is\ndesignated with parentheses.\n\nBack-references and subexpressions are used in two cases: in the\nregular expression search pattern, and in the REPLACEMENT part of the\n's' command (*note Regular Expression Addresses: Regexp Addresses. and\n*note The \"s\" Command::).\n\nIn a regular expression pattern, back-references are used to match\nthe same content as a previously matched subexpression.  In the\nfollowing example, the subexpression is '.' - any single character\n(being surrounded by parentheses makes it a subexpression).  The\nback-reference '\\1' asks to match the same content (same character) as\nthe sub-expression.\n\nThe command below matches words starting with any character, followed\nby the letter 'o', followed by the same character as the first.\n\n$ sed -E -n '/^(.)o\\1$/p' /usr/share/dict/words\nbob\nmom\nnon\npop\nsos\ntot\nwow\n\nMultiple subexpressions are automatically numbered from\nleft-to-right.  This command searches for 6-letter palindromes (the\nfirst three letters are 3 subexpressions, followed by 3 back-references\nin reverse order):\n\n$ sed -E -n '/^(.)(.)(.)\\3\\2\\1$/p' /usr/share/dict/words\nredder\n\nIn the 's' command, back-references can be used in the REPLACEMENT\npart to refer back to subexpressions in the REGEXP part.\n\nThe following example uses two subexpressions in the regular\nexpression to match two space-separated words.  The back-references in\nthe REPLACEMENT part prints the words in a different order:\n\n$ echo \"James Bond\" | sed -E 's/(.*) (.*)/The name is \\2, \\1 \\2./'\nThe name is Bond, James Bond.\n\nWhen used with alternation, if the group does not participate in the\nmatch then the back-reference makes the whole match fail.  For example,\n'a(.)|b\\1' will not match 'ba'.  When multiple regular expressions are\ngiven with '-e' or from a file ('-f FILE'), back-references are local to\neach expression.\n\nFile: sed.info,  Node: Escapes,  Next: Locale Considerations,  Prev: Back-references and Subexpressions,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.8 Escape Sequences - specifying special characters",
                    "content": "Until this chapter, we have only encountered escapes of the form '\\^',\nwhich tell 'sed' not to interpret the circumflex as a special character,\nbut rather to take it literally.  For example, '\\*' matches a single\nasterisk rather than zero or more backslashes.\n\nThis chapter introduces another kind of escape(1)--that is, escapes\nthat are applied to a character or sequence of characters that\nordinarily are taken literally, and that 'sed' replaces with a special\ncharacter.  This provides a way of encoding non-printable characters in\npatterns in a visible manner.  There is no restriction on the appearance\nof non-printing characters in a 'sed' script but when a script is being\nprepared in the shell or by text editing, it is usually easier to use\none of the following escape sequences than the binary character it\nrepresents:\n\nThe list of these escapes is:\n\n'\\a'\nProduces or matches a BEL character, that is an \"alert\" (ASCII 7).\n\n'\\f'\nProduces or matches a form feed (ASCII 12).\n\n'\\n'\nProduces or matches a newline (ASCII 10).\n\n'\\r'\nProduces or matches a carriage return (ASCII 13).\n\n'\\t'\nProduces or matches a horizontal tab (ASCII 9).\n\n'\\v'\nProduces or matches a so called \"vertical tab\" (ASCII 11).\n\n'\\cX'\nProduces or matches 'CONTROL-X', where X is any character.  The\nprecise effect of '\\cX' is as follows: if X is a lower case letter,\nit is converted to upper case.  Then bit 6 of the character (hex\n40) is inverted.  Thus '\\cz' becomes hex 1A, but '\\c{' becomes hex\n3B, while '\\c;' becomes hex 7B.\n\n'\\dXXX'\nProduces or matches a character whose decimal ASCII value is XXX.\n\n'\\oXXX'\nProduces or matches a character whose octal ASCII value is XXX.\n\n'\\xXX'\nProduces or matches a character whose hexadecimal ASCII value is\nXX.\n\n'\\b' (backspace) was omitted because of the conflict with the\nexisting \"word boundary\" meaning.\n\n\nGNU 'sed' processes escape sequences before passing the text onto the\nregular-expression matching of the 's///' command and Address matching.\nThus the follwing two commands are equivalent ('0x5e' is the hexadecimal\nASCII value of the character '^'):\n\n$ echo 'a^c' | sed 's/^/b/'\nba^c\n\n$ echo 'a^c' | sed 's/\\x5e/b/'\nba^c\n\nAs are the following ('0x5b','0x5d' are the hexadecimal ASCII values\nof '[',']', respectively):\n\n$ echo abc | sed 's/[a]/x/'\nXbc\n$ echo abc | sed 's/\\x5ba\\x5d/x/'\nXbc\n\nHowever it is recommended to avoid such special characters due to\nunexpected edge-cases.  For example, the following are not equivalent:\n\n$ echo 'a^c' | sed 's/\\^/b/'\nabc\n\n$ echo 'a^c' | sed 's/\\\\\\x5e/b/'\na^c\n\n---------- Footnotes ----------\n\n(1) All the escapes introduced here are GNU extensions, with the\nexception of '\\n'.  In basic regular expression mode, setting\n'POSIXLYCORRECT' disables them inside bracket expressions.\n\nFile: sed.info,  Node: Locale Considerations,  Prev: Escapes,  Up: sed regular expressions\n"
                },
                {
                    "name": "5.9 Multibyte characters and Locale Considerations",
                    "content": "GNU 'sed' processes valid multibyte characters in multibyte locales\n(e.g.  'UTF-8').  (1)\n\nThe following example uses the Greek letter Capital Sigma (U+03A3,\nUnicode code point '0x03A3').  In a 'UTF-8' locale, 'sed' correctly\nprocesses the Sigma as one character despite it being 2 octets (bytes):\n\n$ locale | grep LANG\nLANG=enUS.UTF-8\n\n$ printf 'a\\u03A3b'\naU+03A3b\n\n$ printf 'a\\u03A3b' | sed 's/./X/g'\nXXX\n\n$ printf 'a\\u03A3b' | od -tx1 -An\n61 ce a3 62\n\nTo force 'sed' to process octets separately, use the 'C' locale (also\nknown as the 'POSIX' locale):\n\n$ printf 'a\\u03A3b' | LCALL=C sed 's/./X/g'\nXXXX\n\n\n'sed''s regular expressions do not match invalid multibyte sequences\nin a multibyte locale.\n\nIn the following examples, the ascii value '0xCE' is an incomplete\nmultibyte character (shown here as U+FFFD). The regular expression '.'\ndoes not match it:\n\n$ printf 'a\\xCEb\\n'\naU+FFFDe\n\n$ printf 'a\\xCEb\\n' | sed 's/./X/g'\nXU+FFFDX\n\n$ printf 'a\\xCEc\\n' | sed 's/./X/g' | od -tx1c -An\n58  ce  58  0a\nX      X   \\n\n\nSimilarly, the 'catch-all' regular expression '.*' does not match the\nentire line:\n\n$ printf 'a\\xCEc\\n' | sed 's/.*//' | od -tx1c -An\nce  63  0a\nc  \\n\n\nGNU 'sed' offers the special 'z' command to clear the current pattern\nspace regardless of invalid multibyte characters (i.e.  it works like\n's/.*//' but also removes invalid multibyte characters):\n\n$ printf 'a\\xCEc\\n' | sed 'z' | od -tx1c -An\n0a\n\\n\n\nAlternatively, force the 'C' locale to process each octet separately\n(every octet is a valid character in the 'C' locale):\n\n$ printf 'a\\xCEc\\n' | LCALL=C sed 's/.*//' | od -tx1c -An\n0a\n\\n\n\n'sed''s inability to process invalid multibyte characters can be used\nto detect such invalid sequences in a file.  In the following examples,\nthe '\\xCE\\xCE' is an invalid multibyte sequence, while '\\xCE\\A3' is a\nvalid multibyte sequence (of the Greek Sigma character).\n\nThe following 'sed' program removes all valid characters using 's/.//g'.\nAny content left in the pattern space (the invalid characters) are added\nto the hold space using the 'H' command.  On the last line ('$'), the\nhold space is retrieved ('x'), newlines are removed ('s/\\n//g'), and any\nremaining octets are printed unambiguously ('l').  Thus, any invalid\nmultibyte sequences are printed as octal values:\n\n$ printf 'ab\\nc\\n\\xCE\\xCEde\\n\\xCE\\xA3f\\n' > invalid.txt\n\n$ cat invalid.txt\nab\nc\nU+FFFDU+FFFDde\nU+03A3f\n\n$ sed -n 's/.//g ; H ; ${x;s/\\n//g;l}' invalid.txt\n\\316\\316$\n\nWith a few more commands, 'sed' can print the exact line number\ncorresponding to each invalid characters (line 3).  These characters can\nthen be removed by forcing the 'C' locale and using octal escape\nsequences:\n\n$ sed -n 's/.//g;=;l' invalid.txt | paste - -  | awk '$2!=\"$\"'\n3       \\316\\316$\n\n$ LCALL=C sed '3s/\\o316\\o316//' invalid.txt > fixed.txt\n\n\nGNU 'sed''s substitute command ('s') supports upper/lower case\nconversions using '\\U','\\L' codes.  These conversions support multibyte\ncharacters:\n\n$ printf 'ABC\\u03a3\\n'\nABCU+03A3\n\n$ printf 'ABC\\u03a3\\n' | sed 's/.*/\\L&/'\nabcU+03C3\n\n*Note The \"s\" Command::.\n\n\nIn other locales, the sorting sequence is not specified, and '[a-d]'\nmight be equivalent to '[abcd]' or to '[aBbCcDd]', or it might fail to\nmatch any character, or the set of characters that it matches might even\nbe erratic.  To obtain the traditional interpretation of bracket\nexpressions, you can use the 'C' locale by setting the 'LCALL'\nenvironment variable to the value 'C'.\n\n# TODO: is there any real-world system/locale where 'A'\n#       is replaced by '-' ?\n$ echo A | sed 's/[a-z]/-/'\nA\n\nTheir interpretation depends on the 'LCCTYPE' locale; for example,\n'[[:alnum:]]' means the character class of numbers and letters in the\ncurrent locale.\n\nTODO: show example of collation\n\n# TODO: this works on glibc systems, not on musl-libc/freebsd/macosx.\n$ printf 'cliché\\n' | LCALL=frFR.utf8 sed 's/[[=e=]]/X/g'\nclichX\n\n---------- Footnotes ----------\n\n(1) Some regexp edge-cases depends on the operating system and libc\nimplementation.  The examples shown are known to work as-expected on\nGNU/Linux systems using glibc.\n\nFile: sed.info,  Node: advanced sed,  Next: Examples,  Prev: sed regular expressions,  Up: Top\n"
                }
            ]
        },
        "6 Advanced 'sed': cycles and buffers": {
            "content": "* Menu:\n\n* Execution Cycle::          How 'sed' works\n* Hold and Pattern Buffers::\n* Multiline techniques::     Using D,G,H,N,P to process multiple lines\n* Branching and flow control::\n\nFile: sed.info,  Node: Execution Cycle,  Next: Hold and Pattern Buffers,  Up: advanced sed\n",
            "subsections": [
                {
                    "name": "6.1 How 'sed' Works",
                    "content": "'sed' maintains two data buffers: the active pattern space, and the\nauxiliary hold space.  Both are initially empty.\n\n'sed' operates by performing the following cycle on each line of\ninput: first, 'sed' reads one line from the input stream, removes any\ntrailing newline, and places it in the pattern space.  Then commands are\nexecuted; each command can have an address associated to it: addresses\nare a kind of condition code, and a command is only executed if the\ncondition is verified before the command is to be executed.\n\nWhen the end of the script is reached, unless the '-n' option is in\nuse, the contents of pattern space are printed out to the output stream,\nadding back the trailing newline if it was removed.(1)  Then the next\ncycle starts for the next input line.\n\nUnless special commands (like 'D') are used, the pattern space is\ndeleted between two cycles.  The hold space, on the other hand, keeps\nits data between cycles (see commands 'h', 'H', 'x', 'g', 'G' to move\ndata between both buffers).\n\n---------- Footnotes ----------\n\n(1) Actually, if 'sed' prints a line without the terminating newline,\nit will nevertheless print the missing newline as soon as more text is\nsent to the same output stream, which gives the \"least expected\nsurprise\" even though it does not make commands like 'sed -n p' exactly\nidentical to 'cat'.\n\nFile: sed.info,  Node: Hold and Pattern Buffers,  Next: Multiline techniques,  Prev: Execution Cycle,  Up: advanced sed\n"
                },
                {
                    "name": "6.2 Hold and Pattern Buffers",
                    "content": "TODO\n\nFile: sed.info,  Node: Multiline techniques,  Next: Branching and flow control,  Prev: Hold and Pattern Buffers,  Up: advanced sed\n"
                },
                {
                    "name": "6.3 Multiline techniques - using D,G,H,N,P to process multiple lines",
                    "content": "Multiple lines can be processed as one buffer using the\n'D','G','H','N','P'.  They are similar to their lowercase counterparts\n('d','g', 'h','n','p'), except that these commands append or subtract\ndata while respecting embedded newlines - allowing adding and removing\nlines from the pattern and hold spaces.\n\nThey operate as follows:\n'D'\ndeletes line from the pattern space until the first newline, and\nrestarts the cycle.\n\n'G'\nappends line from the hold space to the pattern space, with a\nnewline before it.\n\n'H'\nappends line from the pattern space to the hold space, with a\nnewline before it.\n\n'N'\nappends line from the input file to the pattern space.\n\n'P'\nprints line from the pattern space until the first newline.\n\nThe following example illustrates the operation of 'N' and 'D'\ncommands:\n\n$ seq 6 | sed -n 'N;l;D'\n1\\n2$\n2\\n3$\n3\\n4$\n4\\n5$\n5\\n6$\n\n1. 'sed' starts by reading the first line into the pattern space (i.e.\n'1').\n2. At the beginning of every cycle, the 'N' command appends a newline\nand the next line to the pattern space (i.e.  '1', '\\n', '2' in the\nfirst cycle).\n3. The 'l' command prints the content of the pattern space\nunambiguously.\n4. The 'D' command then removes the content of pattern space up to the\nfirst newline (leaving '2' at the end of the first cycle).\n5. At the next cycle the 'N' command appends a newline and the next\ninput line to the pattern space (e.g.  '2', '\\n', '3').\n\nA common technique to process blocks of text such as paragraphs\n(instead of line-by-line) is using the following construct:\n\nsed '/./{H;$!d} ; x ; s/REGEXP/REPLACEMENT/'\n\n1. The first expression, '/./{H;$!d}' operates on all non-empty lines,\nand adds the current line (in the pattern space) to the hold space.\nOn all lines except the last, the pattern space is deleted and the\ncycle is restarted.\n\n2. The other expressions 'x' and 's' are executed only on empty lines\n(i.e.  paragraph separators).  The 'x' command fetches the\naccumulated lines from the hold space back to the pattern space.\nThe 's///' command then operates on all the text in the paragraph\n(including the embedded newlines).\n\nThe following example demonstrates this technique:\n$ cat input.txt\na a a aa aaa\naaaa aaaa aa\naaaa aaa aaa\n\nbbbb bbb bbb\nbb bb bbb bb\nbbbbbbbb bbb\n\nccc ccc cccc\ncccc ccccc c\ncc cc cc cc\n\n$ sed '/./{H;$!d} ; x ; s/^/\\nSTART-->/ ; s/$/\\n<--END/' input.txt\n\nSTART-->\na a a aa aaa\naaaa aaaa aa\naaaa aaa aaa\n<--END\n\nSTART-->\nbbbb bbb bbb\nbb bb bbb bb\nbbbbbbbb bbb\n<--END\n\nSTART-->\nccc ccc cccc\ncccc ccccc c\ncc cc cc cc\n<--END\n\nFor more annotated examples, *note Text search across multiple\nlines:: and *note Line length adjustment::.\n\nFile: sed.info,  Node: Branching and flow control,  Prev: Multiline techniques,  Up: advanced sed\n"
                },
                {
                    "name": "6.4 Branching and Flow Control",
                    "content": "The branching commands 'b', 't', and 'T' enable changing the flow of\n'sed' programs.\n\nBy default, 'sed' reads an input line into the pattern buffer, then\ncontinues to processes all commands in order.  Commands without\naddresses affect all lines.  Commands with addresses affect only\nmatching lines.  *Note Execution Cycle:: and *note Addresses overview::.\n\n'sed' does not support a typical 'if/then' construct.  Instead, some\ncommands can be used as conditionals or to change the default flow\ncontrol:\n\n'd'\ndelete (clears) the current pattern space, and restart the program\ncycle without processing the rest of the commands and without\nprinting the pattern space.\n\n'D'\ndelete the contents of the pattern space up to the first newline,\nand restart the program cycle without processing the rest of the\ncommands and without printing the pattern space.\n\n'[addr]X'\n'[addr]{ X ; X ; X }'\n'/regexp/X'\n'/regexp/{ X ; X ; X }'\nAddresses and regular expressions can be used as an 'if/then'\nconditional: If [ADDR] matches the current pattern space, execute\nthe command(s).  For example: The command '/^#/d' means: if the\ncurrent pattern matches the regular expression '^#' (a line\nstarting with a hash), then execute the 'd' command: delete the\nline without printing it, and restart the program cycle\nimmediately.\n\n'b'\nbranch unconditionally (that is: always jump to a label, skipping\nor repeating other commands, without restarting a new cycle).\nCombined with an address, the branch can be conditionally executed\non matched lines.\n\n't'\nbranch conditionally (that is: jump to a label) only if a 's///'\ncommand has succeeded since the last input line was read or another\nconditional branch was taken.\n\n'T'\nsimilar but opposite to the 't' command: branch only if there has\nbeen no successful substitutions since the last input line was\nread.\n\nThe following two 'sed' programs are equivalent.  The first\n(contrived) example uses the 'b' command to skip the 's///' command on\nlines containing '1'.  The second example uses an address with negation\n('!') to perform substitution only on desired lines.  The 'y///' command\nis still executed on all lines:\n\n$ printf '%s\\n' a1 a2 a3 | sed -E '/1/bx ; s/a/z/ ; :x ; y/123/456/'\na4\nz5\nz6\n\n$ printf '%s\\n' a1 a2 a3 | sed -E '/1/!s/a/z/ ; y/123/456/'\na4\nz5\nz6\n\n\nThe 'b','t' and 'T' commands can be followed by a label (typically a\nsingle letter).  Labels are defined with a colon followed by one or more\nletters (e.g.  ':x').  If the label is omitted the branch commands\nrestart the cycle.  Note the difference between branching to a label and\nrestarting the cycle: when a cycle is restarted, 'sed' first prints the\ncurrent content of the pattern space, then reads the next input line\ninto the pattern space; Jumping to a label (even if it is at the\nbeginning of the program) does not print the pattern space and does not\nread the next input line.\n\nThe following program is a no-op.  The 'b' command (the only command\nin the program) does not have a label, and thus simply restarts the\ncycle.  On each cycle, the pattern space is printed and the next input\nline is read:\n\n$ seq 3 | sed b\n1\n2\n3\n\nThe following example is an infinite-loop - it doesn't terminate and\ndoesn't print anything.  The 'b' command jumps to the 'x' label, and a\nnew cycle is never started:\n\n$ seq 3 | sed ':x ; bx'\n\n# The above command requires gnu sed (which supports additional\n# commands following a label, without a newline). A portable equivalent:\n#     sed -e ':x' -e bx\n\nBranching is often complemented with the 'n' or 'N' commands: both\ncommands read the next input line into the pattern space without waiting\nfor the cycle to restart.  Before reading the next input line, 'n'\nprints the current pattern space then empties it, while 'N' appends a\nnewline and the next input line to the pattern space.\n\nConsider the following two examples:\n\n$ seq 3 | sed ':x ; n ; bx'\n1\n2\n3\n\n$ seq 3 | sed ':x ; N ; bx'\n1\n2\n3\n\n* Both examples do not inf-loop, despite never starting a new cycle.\n\n* In the first example, the 'n' commands first prints the content of\nthe pattern space, empties the pattern space then reads the next\ninput line.\n\n* In the second example, the 'N' commands appends the next input line\nto the pattern space (with a newline).  Lines are accumulated in\nthe pattern space until there are no more input lines to read, then\nthe 'N' command terminates the 'sed' program.  When the program\nterminates, the end-of-cycle actions are performed, and the entire\npattern space is printed.\n\n* The second example requires GNU 'sed', because it uses the\nnon-POSIX-standard behavior of 'N'.  See the \"'N' command on the\nlast line\" paragraph in *note Reporting Bugs::.\n\n* To further examine the difference between the two examples, try the\nfollowing commands:\nprintf '%s\\n' aa bb cc dd | sed ':x ; n ; = ; bx'\nprintf '%s\\n' aa bb cc dd | sed ':x ; N ; = ; bx'\nprintf '%s\\n' aa bb cc dd | sed ':x ; n ; s/\\n/*/ ; bx'\nprintf '%s\\n' aa bb cc dd | sed ':x ; N ; s/\\n/*/ ; bx'\n\n\nAs a real-world example of using branching, consider the case of\nquoted-printable (https://en.wikipedia.org/wiki/Quoted-printable) files,\ntypically used to encode email messages.  In these files long lines are\nsplit and marked with a \"soft line break\" consisting of a single '='\ncharacter at the end of the line:\n\n$ cat jaques.txt\nAll the wor=\nld's a stag=\ne,\nAnd all the=\nmen and wo=\nmen merely =\nplayers:\nThey have t=\nheir exits =\nand their e=\nntrances;\nAnd one man=\nin his tim=\ne plays man=\ny parts.\n\nThe following program uses an address match '/=$/' as a conditional:\nIf the current pattern space ends with a '=', it reads the next input\nline using 'N', replaces all '=' characters which are followed by a\nnewline, and unconditionally branches ('b') to the beginning of the\nprogram without restarting a new cycle.  If the pattern space does not\nends with '=', the default action is performed: the pattern space is\nprinted and a new cycle is started:\n\n$ sed ':x ; /=$/ { N ; s/=\\n//g ; bx }' jaques.txt\nAll the world's a stage,\nAnd all the men and women merely players:\nThey have their exits and their entrances;\nAnd one man in his time plays many parts.\n\nHere's an alternative program with a slightly different approach: On\nall lines except the last, 'N' appends the line to the pattern space.  A\nsubstitution command then removes soft line breaks ('=' at the end of a\nline, i.e.  followed by a newline) by replacing them with an empty\nstring.  if the substitution was successful (meaning the pattern space\ncontained a line which should be joined), The conditional branch command\n't' jumps to the beginning of the program without completing or\nrestarting the cycle.  If the substitution failed (meaning there were no\nsoft line breaks), The 't' command will not branch.  Then, 'P' will\nprint the pattern space content until the first newline, and 'D' will\ndelete the pattern space content until the first new line.  (To learn\nmore about 'N', 'P' and 'D' commands *note Multiline techniques::).\n\n$ sed ':x ; $!N ; s/=\\n// ; tx ; P ; D' jaques.txt\nAll the world's a stage,\nAnd all the men and women merely players:\nThey have their exits and their entrances;\nAnd one man in his time plays many parts.\n\nFor more line-joining examples *note Joining lines::.\n\nFile: sed.info,  Node: Examples,  Next: Limitations,  Prev: advanced sed,  Up: Top\n"
                }
            ]
        },
        "7 Some Sample Scripts": {
            "content": "Here are some 'sed' scripts to guide you in the art of mastering 'sed'.\n\n* Menu:\n\n\nUseful one-liners:\n* Joining lines::\n\nSome exotic examples:\n* Centering lines::\n* Increment a number::\n* Rename files to lower case::\n* Print bash environment::\n* Reverse chars of lines::\n* Text search across multiple lines::\n* Line length adjustment::\n\nEmulating standard utilities:\n* tac::                             Reverse lines of files\n* cat -n::                          Numbering lines\n* cat -b::                          Numbering non-blank lines\n* wc -c::                           Counting chars\n* wc -w::                           Counting words\n* wc -l::                           Counting lines\n* head::                            Printing the first lines\n* tail::                            Printing the last lines\n* uniq::                            Make duplicate lines unique\n* uniq -d::                         Print duplicated lines of input\n* uniq -u::                         Remove all duplicated lines\n* cat -s::                          Squeezing blank lines\n\nFile: sed.info,  Node: Joining lines,  Next: Centering lines,  Up: Examples\n",
            "subsections": [
                {
                    "name": "7.1 Joining lines",
                    "content": "This section uses 'N', 'D' and 'P' commands to process multiple lines,\nand the 'b' and 't' commands for branching.  *Note Multiline\ntechniques:: and *note Branching and flow control::.\n\nJoin specific lines (e.g.  if lines 2 and 3 need to be joined):\n\n$ cat lines.txt\nhello\nhel\nlo\nhello\n\n$ sed '2{N;s/\\n//;}' lines.txt\nhello\nhello\nhello\n\nJoin backslash-continued lines:\n\n$ cat 1.txt\nthis \\\nis \\\na \\\nlong \\\nline\nand another \\\nline\n\n$ sed -e ':x /\\\\$/ { N; s/\\\\\\n//g ; bx }'  1.txt\nthis is a long line\nand another line\n\n\n#TODO: The above requires gnu sed.\n#      non-gnu seds need newlines after ':' and 'b'\n\nJoin lines that start with whitespace (e.g SMTP headers):\n\n$ cat 2.txt\nSubject: Hello\nWorld\nContent-Type: multipart/alternative;\nboundary=94eb2c190cc6370f06054535da6a\nDate: Tue, 3 Jan 2017 19:41:16 +0000 (GMT)\nAuthentication-Results: mx.gnu.org;\ndkim=pass header.i=@gnu.org;\nspf=pass\nMessage-ID: <abcdef@gnu.org>\nFrom: John Doe <jdoe@gnu.org>\nTo: Jane Smith <jsmith@gnu.org>\n\n$ sed -E ':a ; $!N ; s/\\n\\s+/ / ; ta ; P ; D' 2.txt\nSubject: Hello World\nContent-Type: multipart/alternative; boundary=94eb2c190cc6370f06054535da6a\nDate: Tue, 3 Jan 2017 19:41:16 +0000 (GMT)\nAuthentication-Results: mx.gnu.org; dkim=pass header.i=@gnu.org; spf=pass\nMessage-ID: <abcdef@gnu.org>\nFrom: John Doe <jdoe@gnu.org>\nTo: Jane Smith <jsmith@gnu.org>\n\n# A portable (non-gnu) variation:\n#   sed -e :a -e '$!N;s/\\n  */ /;ta' -e 'P;D'\n\nFile: sed.info,  Node: Centering lines,  Next: Increment a number,  Prev: Joining lines,  Up: Examples\n"
                },
                {
                    "name": "7.2 Centering Lines",
                    "content": "This script centers all lines of a file on a 80 columns width.  To\nchange that width, the number in '\\{...\\}' must be replaced, and the\nnumber of added spaces also must be changed.\n\nNote how the buffer commands are used to separate parts in the\nregular expressions to be matched--this is a common technique.\n\n#!/usr/bin/sed -f\n\n# Put 80 spaces in the buffer\n1 {\nx\ns/^$/          /\ns/^.*$/&&&&&&&&/\nx\n}\n\n# delete leading and trailing spaces\ny/<TAB>/ /\ns/^ *//\ns/ *$//\n\n# add a newline and 80 spaces to end of line\nG\n\n# keep first 81 chars (80 + a newline)\ns/^\\(.\\{81\\}\\).*$/\\1/\n\n# \\2 matches half of the spaces, which are moved to the beginning\ns/^\\(.*\\)\\n\\(.*\\)\\2/\\2\\1/\n\nFile: sed.info,  Node: Increment a number,  Next: Rename files to lower case,  Prev: Centering lines,  Up: Examples\n"
                },
                {
                    "name": "7.3 Increment a Number",
                    "content": "This script is one of a few that demonstrate how to do arithmetic in\n'sed'.  This is indeed possible,(1) but must be done manually.\n\nTo increment one number you just add 1 to last digit, replacing it by\nthe following digit.  There is one exception: when the digit is a nine\nthe previous digits must be also incremented until you don't have a\nnine.\n\nThis solution by Bruno Haible is very clever and smart because it\nuses a single buffer; if you don't have this limitation, the algorithm\nused in *note Numbering lines: cat -n, is faster.  It works by replacing\ntrailing nines with an underscore, then using multiple 's' commands to\nincrement the last digit, and then again substituting underscores with\nzeros.\n\n#!/usr/bin/sed -f\n\n/[^0-9]/ d\n\n# replace all trailing 9s by  (any other character except digits, could\n# be used)\n:d\ns/9\\(*\\)$/\\1/\ntd\n\n# incr last digit only.  The first line adds a most-significant\n# digit of 1 if we have to add a digit.\n\ns/^\\(*\\)$/1\\1/; tn\ns/8\\(*\\)$/9\\1/; tn\ns/7\\(*\\)$/8\\1/; tn\ns/6\\(*\\)$/7\\1/; tn\ns/5\\(*\\)$/6\\1/; tn\ns/4\\(*\\)$/5\\1/; tn\ns/3\\(*\\)$/4\\1/; tn\ns/2\\(*\\)$/3\\1/; tn\ns/1\\(*\\)$/2\\1/; tn\ns/0\\(*\\)$/1\\1/; tn\n\n:n\ny//0/\n\n---------- Footnotes ----------\n\n(1) 'sed' guru Greg Ubben wrote an implementation of the 'dc' RPN\ncalculator!  It is distributed together with sed.\n\nFile: sed.info,  Node: Rename files to lower case,  Next: Print bash environment,  Prev: Increment a number,  Up: Examples\n"
                },
                {
                    "name": "7.4 Rename Files to Lower Case",
                    "content": "This is a pretty strange use of 'sed'.  We transform text, and transform\nit to be shell commands, then just feed them to shell.  Don't worry,\neven worse hacks are done when using 'sed'; I have seen a script\nconverting the output of 'date' into a 'bc' program!\n\nThe main body of this is the 'sed' script, which remaps the name from\nlower to upper (or vice-versa) and even checks out if the remapped name\nis the same as the original name.  Note how the script is parameterized\nusing shell variables and proper quoting.\n\n#! /bin/sh\n# rename files to lower/upper case...\n#\n# usage:\n#    move-to-lower *\n#    move-to-upper *\n# or\n#    move-to-lower -R .\n#    move-to-upper -R .\n#\n\nhelp()\n{\ncat << eof\nUsage: $0 [-n] [-r] [-h] files...\n\n-n      do nothing, only see what would be done\n-R      recursive (use find)\n-h      this message\nfiles   files to remap to lower case\n\nExamples:\n$0 -n *        (see if everything is ok, then...)\n$0 *\n\n$0 -R .\n\neof\n}\n\napplycmd='sh'\nfinder='echo \"$@\" | tr \" \" \"\\n\"'\nfilesonly=\n\nwhile :\ndo\ncase \"$1\" in\n-n) applycmd='cat' ;;\n-R) finder='find \"$@\" -type f';;\n-h) help ; exit 1 ;;\n*) break ;;\nesac\nshift\ndone\n\nif [ -z \"$1\" ]; then\necho Usage: $0 [-h] [-n] [-r] files...\nexit 1\nfi\n\nLOWER='abcdefghijklmnopqrstuvwxyz'\nUPPER='ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\ncase `basename $0` in\n*upper*) TO=$UPPER; FROM=$LOWER ;;\n*)       FROM=$UPPER; TO=$LOWER ;;\nesac\n\neval $finder | sed -n '\n\n# remove all trailing slashes\ns/\\/*$//\n\n# add ./ if there is no path, only a filename\n/\\//! s/^/.\\//\n\n# save path+filename\nh\n\n# remove path\ns/.*\\///\n\n# do conversion only on filename\ny/'$FROM'/'$TO'/\n\n# now line contains original path+file, while\n# hold space contains the new filename\nx\n\n# add converted file name to line, which now contains\n# path/file-name\\nconverted-file-name\nG\n\n# check if converted file name is equal to original file name,\n# if it is, do not print anything\n/^.*\\/\\(.*\\)\\n\\1/b\n\n# escape special characters for the shell\ns/[\"$`\\\\]/\\\\&/g\n\n# now, transform path/fromfile\\n, into\n# mv path/fromfile path/tofile and print it\ns/^\\(.*\\/\\)\\(.*\\)\\n\\(.*\\)$/mv \"\\1\\2\" \"\\1\\3\"/p\n\n' | $applycmd\n\nFile: sed.info,  Node: Print bash environment,  Next: Reverse chars of lines,  Prev: Rename files to lower case,  Up: Examples\n"
                },
                {
                    "name": "7.5 Print 'bash' Environment",
                    "content": "This script strips the definition of the shell functions from the output\nof the 'set' Bourne-shell command.\n\n#!/bin/sh\n\nset | sed -n '\n:x\n\n# if no occurrence of \"=()\" print and load next line\n/=()/! { p; b; }\n/ () $/! { p; b; }\n\n# possible start of functions section\n# save the line in case this is a var like FOO=\"() \"\nh\n\n# if the next line has a brace, we quit because\n# nothing comes after functions\nn\n/^{/ q\n\n# print the old line\nx; p\n\n# work on the new line now\nx; bx\n'\n\nFile: sed.info,  Node: Reverse chars of lines,  Next: Text search across multiple lines,  Prev: Print bash environment,  Up: Examples\n"
                },
                {
                    "name": "7.6 Reverse Characters of Lines",
                    "content": "This script can be used to reverse the position of characters in lines.\nThe technique moves two characters at a time, hence it is faster than\nmore intuitive implementations.\n\nNote the 'tx' command before the definition of the label.  This is\noften needed to reset the flag that is tested by the 't' command.\n\nImaginative readers will find uses for this script.  An example is\nreversing the output of 'banner'.(1)\n\n#!/usr/bin/sed -f\n\n/../! b\n\n# Reverse a line.  Begin embedding the line between two newlines\ns/^.*$/\\\n&\\\n/\n\n# Move first character at the end.  The regexp matches until\n# there are zero or one characters between the markers\ntx\n:x\ns/\\(\\n.\\)\\(.*\\)\\(.\\n\\)/\\3\\2\\1/\ntx\n\n# Remove the newline markers\ns/\\n//g\n\n---------- Footnotes ----------\n\n(1) This requires another script to pad the output of banner; for\nexample\n\n#! /bin/sh\n\nbanner -w $1 $2 $3 $4 |\nsed -e :a -e '/^.\\{0,'$1'\\}$/ { s/$/ /; ba; }' |\n~/sedscripts/reverseline.sed\n\nFile: sed.info,  Node: Text search across multiple lines,  Next: Line length adjustment,  Prev: Reverse chars of lines,  Up: Examples\n"
                },
                {
                    "name": "7.7 Text search across multiple lines",
                    "content": "This section uses 'N' and 'D' commands to search for consecutive words\nspanning multiple lines.  *Note Multiline techniques::.\n\nThese examples deal with finding doubled occurrences of words in a\ndocument.\n\nFinding doubled words in a single line is easy using GNU 'grep' and\nsimilarly with GNU 'sed':\n\n$ cat two-cities-dup1.txt\nIt was the best of times,\nit was the worst of times,\nit was the the age of wisdom,\nit was the age of foolishness,\n\n$ grep -E '\\b(\\w+)\\s+\\1\\b' two-cities-dup1.txt\nit was the the age of wisdom,\n\n$ grep -n -E '\\b(\\w+)\\s+\\1\\b' two-cities-dup1.txt\n3:it was the the age of wisdom,\n\n$ sed -En '/\\b(\\w+)\\s+\\1\\b/p' two-cities-dup1.txt\nit was the the age of wisdom,\n\n$ sed -En '/\\b(\\w+)\\s+\\1\\b/{=;p}' two-cities-dup1.txt\n3\nit was the the age of wisdom,\n\n* The regular expression '\\b\\w+\\s+' searches for word-boundary\n('\\b'), followed by one-or-more word-characters ('\\w+'), followed\nby whitespace ('\\s+').  *Note regexp extensions::.\n\n* Adding parentheses around the '(\\w+)' expression creates a\nsubexpression.  The regular expression pattern '(PATTERN)\\s+\\1'\ndefines a subexpression (in the parentheses) followed by a\nback-reference, separated by whitespace.  A successful match means\nthe PATTERN was repeated twice in succession.  *Note\nBack-references and Subexpressions::.\n\n* The word-boundery expression ('\\b') at both ends ensures partial\nwords are not matched (e.g.  'the then' is not a desired match).\n\n* The '-E' option enables extended regular expression syntax,\nalleviating the need to add backslashes before the parenthesis.\n*Note ERE syntax::.\n\nWhen the doubled word span two lines the above regular expression\nwill not find them as 'grep' and 'sed' operate line-by-line.\n\nBy using 'N' and 'D' commands, 'sed' can apply regular expressions on\nmultiple lines (that is, multiple lines are stored in the pattern space,\nand the regular expression works on it):\n\n$ cat two-cities-dup2.txt\nIt was the best of times, it was the\nworst of times, it was the\nthe age of wisdom,\nit was the age of foolishness,\n\n$ sed -En '{N; /\\b(\\w+)\\s+\\1\\b/{=;p} ; D}'  two-cities-dup2.txt\n3\nworst of times, it was the\nthe age of wisdom,\n\n* The 'N' command appends the next line to the pattern space (thus\nensuring it contains two consecutive lines in every cycle).\n\n* The regular expression uses '\\s+' for word separator which matches\nboth spaces and newlines.\n\n* The regular expression matches, the entire pattern space is printed\nwith 'p'.  No lines are printed by default due to the '-n' option.\n\n* The 'D' removes the first line from the pattern space (up until the\nfirst newline), readying it for the next cycle.\n\nSee the GNU 'coreutils' manual for an alternative solution using 'tr\n-s' and 'uniq' at\n<https://gnu.org/s/coreutils/manual/htmlnode/Squeezing-and-deleting.html>.\n\nFile: sed.info,  Node: Line length adjustment,  Next: tac,  Prev: Text search across multiple lines,  Up: Examples\n"
                },
                {
                    "name": "7.8 Line length adjustment",
                    "content": "This section uses 'N' and 'D' commands to search for consecutive words\nspanning multiple lines, and the 'b' command for branching.  *Note\nMultiline techniques:: and *note Branching and flow control::.\n\nThis (somewhat contrived) example deal with formatting and wrapping\nlines of text of the following input file:\n\n$ cat two-cities-mix.txt\nIt was the best of times, it was\nthe worst of times, it\nwas the age of\nwisdom,\nit\nwas\nthe age\nof foolishness,\n\nThe following sed program wraps lines at 40 characters:\n$ cat wrap40.sed\n# outer loop\n:x\n\n# Appead a newline followed by the next input line to the pattern buffer\nN\n\n# Remove all newlines from the pattern buffer\ns/\\n/ /g\n\n\n# Inner loop\n:y\n\n# Add a newline after the first 40 characters\ns/(.{40,40})/\\1\\n/\n\n# If there is a newline in the pattern buffer\n# (i.e. the previous substitution added a newline)\n/\\n/ {\n# There are newlines in the pattern buffer -\n# print the content until the first newline.\nP\n\n# Remove the printed characters and the first newline\ns/.*\\n//\n\n# branch to label 'y' - repeat inner loop\nby\n}\n\n# No newlines in the pattern buffer - Branch to label 'x' (outer loop)\n# and read the next input line\nbx\n\nThe wrapped output:\n$ sed -E -f wrap40.sed two-cities-mix.txt\nIt was the best of times, it was the wor\nst of times, it was the age of wisdom, i\nt was the age of foolishness,\n\nFile: sed.info,  Node: tac,  Next: cat -n,  Prev: Line length adjustment,  Up: Examples\n"
                },
                {
                    "name": "7.9 Reverse Lines of Files",
                    "content": "This one begins a series of totally useless (yet interesting) scripts\nemulating various Unix commands.  This, in particular, is a 'tac'\nworkalike.\n\nNote that on implementations other than GNU 'sed' this script might\neasily overflow internal buffers.\n\n#!/usr/bin/sed -nf\n\n# reverse all lines of input, i.e. first line became last, ...\n\n# from the second line, the buffer (which contains all previous lines)\n# is *appended* to current line, so, the order will be reversed\n1! G\n\n# on the last line we're done -- print everything\n$ p\n\n# store everything on the buffer again\nh\n\nFile: sed.info,  Node: cat -n,  Next: cat -b,  Prev: tac,  Up: Examples\n"
                },
                {
                    "name": "7.10 Numbering Lines",
                    "content": "This script replaces 'cat -n'; in fact it formats its output exactly\nlike GNU 'cat' does.\n\nOf course this is completely useless and for two reasons: first,\nbecause somebody else did it in C, second, because the following\nBourne-shell script could be used for the same purpose and would be much\nfaster:\n\n#! /bin/sh\nsed -e \"=\" $@ | sed -e '\ns/^/      /\nN\ns/^ *\\(......\\)\\n/\\1  /\n'\n\nIt uses 'sed' to print the line number, then groups lines two by two\nusing 'N'.  Of course, this script does not teach as much as the one\npresented below.\n\nThe algorithm used for incrementing uses both buffers, so the line is\nprinted as soon as possible and then discarded.  The number is split so\nthat changing digits go in a buffer and unchanged ones go in the other;\nthe changed digits are modified in a single step (using a 'y' command).\nThe line number for the next line is then composed and stored in the\nhold space, to be used in the next iteration.\n\n#!/usr/bin/sed -nf\n\n# Prime the pump on the first line\nx\n/^$/ s/^.*$/1/\n\n# Add the correct line number before the pattern\nG\nh\n\n# Format it and print it\ns/^/      /\ns/^ *\\(......\\)\\n/\\1  /p\n\n# Get the line number from hold space; add a zero\n# if we're going to add a digit on the next line\ng\ns/\\n.*$//\n/^9*$/ s/^/0/\n\n# separate changing/unchanged digits with an x\ns/.9*$/x&/\n\n# keep changing digits in hold space\nh\ns/^.*x//\ny/0123456789/1234567890/\nx\n\n# keep unchanged digits in pattern space\ns/x.*$//\n\n# compose the new number, remove the newline implicitly added by G\nG\ns/\\n//\nh\n\nFile: sed.info,  Node: cat -b,  Next: wc -c,  Prev: cat -n,  Up: Examples\n"
                },
                {
                    "name": "7.11 Numbering Non-blank Lines",
                    "content": "Emulating 'cat -b' is almost the same as 'cat -n'--we only have to\nselect which lines are to be numbered and which are not.\n\nThe part that is common to this script and the previous one is not\ncommented to show how important it is to comment 'sed' scripts\nproperly...\n\n#!/usr/bin/sed -nf\n\n/^$/ {\np\nb\n}\n\n# Same as cat -n from now\nx\n/^$/ s/^.*$/1/\nG\nh\ns/^/      /\ns/^ *\\(......\\)\\n/\\1  /p\nx\ns/\\n.*$//\n/^9*$/ s/^/0/\ns/.9*$/x&/\nh\ns/^.*x//\ny/0123456789/1234567890/\nx\ns/x.*$//\nG\ns/\\n//\nh\n\nFile: sed.info,  Node: wc -c,  Next: wc -w,  Prev: cat -b,  Up: Examples\n"
                },
                {
                    "name": "7.12 Counting Characters",
                    "content": "This script shows another way to do arithmetic with 'sed'.  In this case\nwe have to add possibly large numbers, so implementing this by\nsuccessive increments would not be feasible (and possibly even more\ncomplicated to contrive than this script).\n\nThe approach is to map numbers to letters, kind of an abacus\nimplemented with 'sed'.  'a's are units, 'b's are tens and so on: we\nsimply add the number of characters on the current line as units, and\nthen propagate the carry to tens, hundreds, and so on.\n\nAs usual, running totals are kept in hold space.\n\nOn the last line, we convert the abacus form back to decimal.  For\nthe sake of variety, this is done with a loop rather than with some 80\n's' commands(1): first we convert units, removing 'a's from the number;\nthen we rotate letters so that tens become 'a's, and so on until no more\nletters remain.\n\n#!/usr/bin/sed -nf\n\n# Add n+1 a's to hold space (+1 is for the newline)\ns/./a/g\nH\nx\ns/\\n/a/\n\n# Do the carry.  The t's and b's are not necessary,\n# but they do speed up the thing\nt a\n: a;  s/aaaaaaaaaa/b/g; t b; b done\n: b;  s/bbbbbbbbbb/c/g; t c; b done\n: c;  s/cccccccccc/d/g; t d; b done\n: d;  s/dddddddddd/e/g; t e; b done\n: e;  s/eeeeeeeeee/f/g; t f; b done\n: f;  s/ffffffffff/g/g; t g; b done\n: g;  s/gggggggggg/h/g; t h; b done\n: h;  s/hhhhhhhhhh//g\n\n: done\n$! {\nh\nb\n}\n\n# On the last line, convert back to decimal\n\n: loop\n/a/! s/[b-h]*/&0/\ns/aaaaaaaaa/9/\ns/aaaaaaaa/8/\ns/aaaaaaa/7/\ns/aaaaaa/6/\ns/aaaaa/5/\ns/aaaa/4/\ns/aaa/3/\ns/aa/2/\ns/a/1/\n\n: next\ny/bcdefgh/abcdefg/\n/[a-h]/ b loop\np\n\n---------- Footnotes ----------\n\n(1) Some implementations have a limit of 199 commands per script\n\nFile: sed.info,  Node: wc -w,  Next: wc -l,  Prev: wc -c,  Up: Examples\n"
                },
                {
                    "name": "7.13 Counting Words",
                    "content": "This script is almost the same as the previous one, once each of the\nwords on the line is converted to a single 'a' (in the previous script\neach letter was changed to an 'a').\n\nIt is interesting that real 'wc' programs have optimized loops for\n'wc -c', so they are much slower at counting words rather than\ncharacters.  This script's bottleneck, instead, is arithmetic, and hence\nthe word-counting one is faster (it has to manage smaller numbers).\n\nAgain, the common parts are not commented to show the importance of\ncommenting 'sed' scripts.\n\n#!/usr/bin/sed -nf\n\n# Convert words to a's\ns/[ <TAB>][ <TAB>]*/ /g\ns/^/ /\ns/ [^ ][^ ]*/a /g\ns/ //g\n\n# Append them to hold space\nH\nx\ns/\\n//\n\n# From here on it is the same as in wc -c.\n/aaaaaaaaaa/! bx;   s/aaaaaaaaaa/b/g\n/bbbbbbbbbb/! bx;   s/bbbbbbbbbb/c/g\n/cccccccccc/! bx;   s/cccccccccc/d/g\n/dddddddddd/! bx;   s/dddddddddd/e/g\n/eeeeeeeeee/! bx;   s/eeeeeeeeee/f/g\n/ffffffffff/! bx;   s/ffffffffff/g/g\n/gggggggggg/! bx;   s/gggggggggg/h/g\ns/hhhhhhhhhh//g\n:x\n$! { h; b; }\n:y\n/a/! s/[b-h]*/&0/\ns/aaaaaaaaa/9/\ns/aaaaaaaa/8/\ns/aaaaaaa/7/\ns/aaaaaa/6/\ns/aaaaa/5/\ns/aaaa/4/\ns/aaa/3/\ns/aa/2/\ns/a/1/\ny/bcdefgh/abcdefg/\n/[a-h]/ by\np\n\nFile: sed.info,  Node: wc -l,  Next: head,  Prev: wc -w,  Up: Examples\n"
                },
                {
                    "name": "7.14 Counting Lines",
                    "content": "No strange things are done now, because 'sed' gives us 'wc -l'\nfunctionality for free!!!  Look:\n\n#!/usr/bin/sed -nf\n$=\n\nFile: sed.info,  Node: head,  Next: tail,  Prev: wc -l,  Up: Examples\n"
                },
                {
                    "name": "7.15 Printing the First Lines",
                    "content": "This script is probably the simplest useful 'sed' script.  It displays\nthe first 10 lines of input; the number of displayed lines is right\nbefore the 'q' command.\n\n#!/usr/bin/sed -f\n10q\n\nFile: sed.info,  Node: tail,  Next: uniq,  Prev: head,  Up: Examples\n"
                },
                {
                    "name": "7.16 Printing the Last Lines",
                    "content": "Printing the last N lines rather than the first is more complex but\nindeed possible.  N is encoded in the second line, before the bang\ncharacter.\n\nThis script is similar to the 'tac' script in that it keeps the final\noutput in the hold space and prints it at the end:\n\n#!/usr/bin/sed -nf\n\n1! {; H; g; }\n1,10 !s/[^\\n]*\\n//\n$p\nh\n\nMainly, the scripts keeps a window of 10 lines and slides it by\nadding a line and deleting the oldest (the substitution command on the\nsecond line works like a 'D' command but does not restart the loop).\n\nThe \"sliding window\" technique is a very powerful way to write\nefficient and complex 'sed' scripts, because commands like 'P' would\nrequire a lot of work if implemented manually.\n\nTo introduce the technique, which is fully demonstrated in the rest\nof this chapter and is based on the 'N', 'P' and 'D' commands, here is\nan implementation of 'tail' using a simple \"sliding window.\"\n\nThis looks complicated but in fact the working is the same as the\nlast script: after we have kicked in the appropriate number of lines,\nhowever, we stop using the hold space to keep inter-line state, and\ninstead use 'N' and 'D' to slide pattern space by one line:\n\n#!/usr/bin/sed -f\n\n1h\n2,10 {; H; g; }\n$q\n1,9d\nN\nD\n\nNote how the first, second and fourth line are inactive after the\nfirst ten lines of input.  After that, all the script does is: exiting\non the last line of input, appending the next input line to pattern\nspace, and removing the first line.\n\nFile: sed.info,  Node: uniq,  Next: uniq -d,  Prev: tail,  Up: Examples\n"
                },
                {
                    "name": "7.17 Make Duplicate Lines Unique",
                    "content": "This is an example of the art of using the 'N', 'P' and 'D' commands,\nprobably the most difficult to master.\n\n#!/usr/bin/sed -f\nh\n\n:b\n# On the last line, print and exit\n$b\nN\n/^\\(.*\\)\\n\\1$/ {\n# The two lines are identical.  Undo the effect of\n# the n command.\ng\nbb\n}\n\n# If the N command had added the last line, print and exit\n$b\n\n# The lines are different; print the first and go\n# back working on the second.\nP\nD\n\nAs you can see, we maintain a 2-line window using 'P' and 'D'.  This\ntechnique is often used in advanced 'sed' scripts.\n\nFile: sed.info,  Node: uniq -d,  Next: uniq -u,  Prev: uniq,  Up: Examples\n"
                },
                {
                    "name": "7.18 Print Duplicated Lines of Input",
                    "content": "This script prints only duplicated lines, like 'uniq -d'.\n\n#!/usr/bin/sed -nf\n\n$b\nN\n/^\\(.*\\)\\n\\1$/ {\n# Print the first of the duplicated lines\ns/.*\\n//\np\n\n# Loop until we get a different line\n:b\n$b\nN\n/^\\(.*\\)\\n\\1$/ {\ns/.*\\n//\nbb\n}\n}\n\n# The last line cannot be followed by duplicates\n$b\n\n# Found a different one.  Leave it alone in the pattern space\n# and go back to the top, hunting its duplicates\nD\n\nFile: sed.info,  Node: uniq -u,  Next: cat -s,  Prev: uniq -d,  Up: Examples\n"
                },
                {
                    "name": "7.19 Remove All Duplicated Lines",
                    "content": "This script prints only unique lines, like 'uniq -u'.\n\n#!/usr/bin/sed -f\n\n# Search for a duplicate line --- until that, print what you find.\n$b\nN\n/^\\(.*\\)\\n\\1$/ ! {\nP\nD\n}\n\n:c\n# Got two equal lines in pattern space.  At the\n# end of the file we simply exit\n$d\n\n# Else, we keep reading lines with N until we\n# find a different one\ns/.*\\n//\nN\n/^\\(.*\\)\\n\\1$/ {\nbc\n}\n\n# Remove the last instance of the duplicate line\n# and go back to the top\nD\n\nFile: sed.info,  Node: cat -s,  Prev: uniq -u,  Up: Examples\n"
                },
                {
                    "name": "7.20 Squeezing Blank Lines",
                    "content": "As a final example, here are three scripts, of increasing complexity and\nspeed, that implement the same function as 'cat -s', that is squeezing\nblank lines.\n\nThe first leaves a blank line at the beginning and end if there are\nsome already.\n\n#!/usr/bin/sed -f\n\n# on empty lines, join with next\n# Note there is a star in the regexp\n:x\n/^\\n*$/ {\nN\nbx\n}\n\n# now, squeeze all '\\n', this can be also done by:\n# s/^\\(\\n\\)*/\\1/\ns/\\n*/\\\n/\n\nThis one is a bit more complex and removes all empty lines at the\nbeginning.  It does leave a single blank line at end if one was there.\n\n#!/usr/bin/sed -f\n\n# delete all leading empty lines\n1,/^./{\n/./!d\n}\n\n# on an empty line we remove it and all the following\n# empty lines, but one\n:x\n/./!{\nN\ns/^\\n$//\ntx\n}\n\nThis removes leading and trailing blank lines.  It is also the\nfastest.  Note that loops are completely done with 'n' and 'b', without\nrelying on 'sed' to restart the script automatically at the end of a\nline.\n\n#!/usr/bin/sed -nf\n\n# delete all (leading) blanks\n/./!d\n\n# get here: so there is a non empty\n:x\n# print it\np\n# get next\nn\n# got chars? print it again, etc...\n/./bx\n\n# no, don't have chars: got an empty line\n:z\n# get next, if last line we finish here so no trailing\n# empty lines are written\nn\n# also empty? then ignore it, and get next... this will\n# remove ALL empty lines\n/./!bz\n\n# all empty lines were deleted/ignored, but we have a non empty.  As\n# what we want to do is to squeeze, insert a blank line artificially\ni\\\n\nbx\n\nFile: sed.info,  Node: Limitations,  Next: Other Resources,  Prev: Examples,  Up: Top\n"
                }
            ]
        },
        "8 GNU 'sed''s Limitations and Non-limitations": {
            "content": "For those who want to write portable 'sed' scripts, be aware that some\nimplementations have been known to limit line lengths (for the pattern\nand hold spaces) to be no more than 4000 bytes.  The POSIX standard\nspecifies that conforming 'sed' implementations shall support at least\n8192 byte line lengths.  GNU 'sed' has no built-in limit on line length;\nas long as it can 'malloc()' more (virtual) memory, you can feed or\nconstruct lines as long as you like.\n\nHowever, recursion is used to handle subpatterns and indefinite\nrepetition.  This means that the available stack space may limit the\nsize of the buffer that can be processed by certain patterns.\n\nFile: sed.info,  Node: Other Resources,  Next: Reporting Bugs,  Prev: Limitations,  Up: Top\n",
            "subsections": []
        },
        "9 Other Resources for Learning About 'sed'": {
            "content": "For up to date information about GNU 'sed' please visit\n<https://www.gnu.org/software/sed/>.\n\nSend general questions and suggestions to <sed-devel@gnu.org>.  Visit\nthe mailing list archives for past discussions at\n<https://lists.gnu.org/archive/html/sed-devel/>.\n\nThe following resources provide information about 'sed' (both GNU\n'sed' and other variations).  Note these not maintained by GNU 'sed'\ndevelopers.\n\n* sed '$HOME': <http://sed.sf.net>\n\n* sed FAQ: <http://sed.sf.net/sedfaq.html>\n\n* seder's grabbag: <http://sed.sf.net/grabbag>\n\n* The 'sed-users' mailing list maintained by Sven Guckes:\n<http://groups.yahoo.com/group/sed-users/> (note this is not the\nGNU 'sed' mailing list).\n\nFile: sed.info,  Node: Reporting Bugs,  Next: GNU Free Documentation License,  Prev: Other Resources,  Up: Top\n",
            "subsections": []
        },
        "10 Reporting Bugs": {
            "content": "Email bug reports to <bug-sed@gnu.org>.  Also, please include the output\nof 'sed --version' in the body of your report if at all possible.\n\nPlease do not send a bug report like this:\n\nwhile building frobme-1.3.4\n$ configure\nerror-> sed: file sedscr line 1: Unknown option to 's'\n\nIf GNU 'sed' doesn't configure your favorite package, take a few\nextra minutes to identify the specific problem and make a stand-alone\ntest case.  Unlike other programs such as C compilers, making such test\ncases for 'sed' is quite simple.\n\nA stand-alone test case includes all the data necessary to perform\nthe test, and the specific invocation of 'sed' that causes the problem.\nThe smaller a stand-alone test case is, the better.  A test case should\nnot involve something as far removed from 'sed' as \"try to configure\nfrobme-1.3.4\".  Yes, that is in principle enough information to look for\nthe bug, but that is not a very practical prospect.\n\nHere are a few commonly reported bugs that are not bugs.\n\n'N' command on the last line\n\nMost versions of 'sed' exit without printing anything when the 'N'\ncommand is issued on the last line of a file.  GNU 'sed' prints\npattern space before exiting unless of course the '-n' command\nswitch has been specified.  This choice is by design.\n\nDefault behavior (gnu extension, non-POSIX conforming):\n$ seq 3 | sed N\n1\n2\n3\nTo force POSIX-conforming behavior:\n$ seq 3 | sed --posix N\n1\n2\n\nFor example, the behavior of\nsed N foo bar\nwould depend on whether foo has an even or an odd number of\nlines(1).  Or, when writing a script to read the next few lines\nfollowing a pattern match, traditional implementations of 'sed'\nwould force you to write something like\n/foo/{ $!N; $!N; $!N; $!N; $!N; $!N; $!N; $!N; $!N }\ninstead of just\n/foo/{ N;N;N;N;N;N;N;N;N; }\n\nIn any case, the simplest workaround is to use '$d;N' in scripts\nthat rely on the traditional behavior, or to set the\n'POSIXLYCORRECT' variable to a non-empty value.\n\nRegex syntax clashes (problems with backslashes)\n'sed' uses the POSIX basic regular expression syntax.  According to\nthe standard, the meaning of some escape sequences is undefined in\nthis syntax; notable in the case of 'sed' are '\\|', '\\+', '\\?',\n'\\`', '\\'', '\\<', '\\>', '\\b', '\\B', '\\w', and '\\W'.\n\nAs in all GNU programs that use POSIX basic regular expressions,\n'sed' interprets these escape sequences as special characters.  So,\n'x\\+' matches one or more occurrences of 'x'.  'abc\\|def' matches\neither 'abc' or 'def'.\n\nThis syntax may cause problems when running scripts written for\nother 'sed's.  Some 'sed' programs have been written with the\nassumption that '\\|' and '\\+' match the literal characters '|' and\n'+'.  Such scripts must be modified by removing the spurious\nbackslashes if they are to be used with modern implementations of\n'sed', like GNU 'sed'.\n\nOn the other hand, some scripts use s|abc\\|def||g to remove\noccurrences of either 'abc' or 'def'.  While this worked until\n'sed' 4.0.x, newer versions interpret this as removing the string\n'abc|def'.  This is again undefined behavior according to POSIX,\nand this interpretation is arguably more robust: older 'sed's, for\nexample, required that the regex matcher parsed '\\/' as '/' in the\ncommon case of escaping a slash, which is again undefined behavior;\nthe new behavior avoids this, and this is good because the regex\nmatcher is only partially under our control.\n\nIn addition, this version of 'sed' supports several escape\ncharacters (some of which are multi-character) to insert\nnon-printable characters in scripts ('\\a', '\\c', '\\d', '\\o', '\\r',\n'\\t', '\\v', '\\x').  These can cause similar problems with scripts\nwritten for other 'sed's.\n\n'-i' clobbers read-only files\n\nIn short, 'sed -i' will let you delete the contents of a read-only\nfile, and in general the '-i' option (*note Invocation: Invoking\nsed.) lets you clobber protected files.  This is not a bug, but\nrather a consequence of how the Unix file system works.\n\nThe permissions on a file say what can happen to the data in that\nfile, while the permissions on a directory say what can happen to\nthe list of files in that directory.  'sed -i' will not ever open\nfor writing a file that is already on disk.  Rather, it will work\non a temporary file that is finally renamed to the original name:\nif you rename or delete files, you're actually modifying the\ncontents of the directory, so the operation depends on the\npermissions of the directory, not of the file.  For this same\nreason, 'sed' does not let you use '-i' on a writable file in a\nread-only directory, and will break hard or symbolic links when\n'-i' is used on such a file.\n\n'0a' does not work (gives an error)\n\nThere is no line 0.  0 is a special address that is only used to\ntreat addresses like '0,/RE/' as active when the script starts: if\nyou write '1,/abc/d' and the first line includes the word 'abc',\nthen that match would be ignored because address ranges must span\nat least two lines (barring the end of the file); but what you\nprobably wanted is to delete every line up to the first one\nincluding 'abc', and this is obtained with '0,/abc/d'.\n\n'[a-z]' is case insensitive\n\nYou are encountering problems with locales.  POSIX mandates that\n'[a-z]' uses the current locale's collation order - in C parlance,\nthat means using 'strcoll(3)' instead of 'strcmp(3)'.  Some locales\nhave a case-insensitive collation order, others don't.\n\nAnother problem is that '[a-z]' tries to use collation symbols.\nThis only happens if you are on the GNU system, using GNU libc's\nregular expression matcher instead of compiling the one supplied\nwith GNU sed.  In a Danish locale, for example, the regular\nexpression '^[a-z]$' matches the string 'aa', because this is a\nsingle collating symbol that comes after 'a' and before 'b'; 'll'\nbehaves similarly in Spanish locales, or 'ij' in Dutch locales.\n\nTo work around these problems, which may cause bugs in shell\nscripts, set the 'LCCOLLATE' and 'LCCTYPE' environment variables\nto 'C'.\n\n's/.*//' does not clear pattern space\n\nThis happens if your input stream includes invalid multibyte\nsequences.  POSIX mandates that such sequences are not matched by\n'.', so that 's/.*//' will not clear pattern space as you would\nexpect.  In fact, there is no way to clear sed's buffers in the\nmiddle of the script in most multibyte locales (including UTF-8\nlocales).  For this reason, GNU 'sed' provides a 'z' command (for\n'zap') as an extension.\n\nTo work around these problems, which may cause bugs in shell\nscripts, set the 'LCCOLLATE' and 'LCCTYPE' environment variables\nto 'C'.\n\n---------- Footnotes ----------\n\n(1) which is the actual \"bug\" that prompted the change in behavior\n\nFile: sed.info,  Node: GNU Free Documentation License,  Next: Concept Index,  Prev: Reporting Bugs,  Up: Top\n",
            "subsections": []
        },
        "Appendix A GNU Free Documentation License": {
            "content": "Version 1.3, 3 November 2008\n\nCopyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.\n<https://fsf.org/>\n\nEveryone is permitted to copy and distribute verbatim copies\nof this license document, but changing it is not allowed.\n\n0. PREAMBLE\n\nThe purpose of this License is to make a manual, textbook, or other\nfunctional and useful document \"free\" in the sense of freedom: to\nassure everyone the effective freedom to copy and redistribute it,\nwith or without modifying it, either commercially or\nnoncommercially.  Secondarily, this License preserves for the\nauthor and publisher a way to get credit for their work, while not\nbeing considered responsible for modifications made by others.\n\nThis License is a kind of \"copyleft\", which means that derivative\nworks of the document must themselves be free in the same sense.\nIt complements the GNU General Public License, which is a copyleft\nlicense designed for free software.\n\nWe have designed this License in order to use it for manuals for\nfree software, because free software needs free documentation: a\nfree program should come with manuals providing the same freedoms\nthat the software does.  But this License is not limited to\nsoftware manuals; it can be used for any textual work, regardless\nof subject matter or whether it is published as a printed book.  We\nrecommend this License principally for works whose purpose is\ninstruction or reference.\n\n1. APPLICABILITY AND DEFINITIONS\n\nThis License applies to any manual or other work, in any medium,\nthat contains a notice placed by the copyright holder saying it can\nbe distributed under the terms of this License.  Such a notice\ngrants a world-wide, royalty-free license, unlimited in duration,\nto use that work under the conditions stated herein.  The\n\"Document\", below, refers to any such manual or work.  Any member\nof the public is a licensee, and is addressed as \"you\".  You accept\nthe license if you copy, modify or distribute the work in a way\nrequiring permission under copyright law.\n\nA \"Modified Version\" of the Document means any work containing the\nDocument or a portion of it, either copied verbatim, or with\nmodifications and/or translated into another language.\n\nA \"Secondary Section\" is a named appendix or a front-matter section\nof the Document that deals exclusively with the relationship of the\npublishers or authors of the Document to the Document's overall\nsubject (or to related matters) and contains nothing that could\nfall directly within that overall subject.  (Thus, if the Document\nis in part a textbook of mathematics, a Secondary Section may not\nexplain any mathematics.)  The relationship could be a matter of\nhistorical connection with the subject or with related matters, or\nof legal, commercial, philosophical, ethical or political position\nregarding them.\n\nThe \"Invariant Sections\" are certain Secondary Sections whose\ntitles are designated, as being those of Invariant Sections, in the\nnotice that says that the Document is released under this License.\nIf a section does not fit the above definition of Secondary then it\nis not allowed to be designated as Invariant.  The Document may\ncontain zero Invariant Sections.  If the Document does not identify\nany Invariant Sections then there are none.\n\nThe \"Cover Texts\" are certain short passages of text that are\nlisted, as Front-Cover Texts or Back-Cover Texts, in the notice\nthat says that the Document is released under this License.  A\nFront-Cover Text may be at most 5 words, and a Back-Cover Text may\nbe at most 25 words.\n\nA \"Transparent\" copy of the Document means a machine-readable copy,\nrepresented in a format whose specification is available to the\ngeneral public, that is suitable for revising the document\nstraightforwardly with generic text editors or (for images composed\nof pixels) generic paint programs or (for drawings) some widely\navailable drawing editor, and that is suitable for input to text\nformatters or for automatic translation to a variety of formats\nsuitable for input to text formatters.  A copy made in an otherwise\nTransparent file format whose markup, or absence of markup, has\nbeen arranged to thwart or discourage subsequent modification by\nreaders is not Transparent.  An image format is not Transparent if\nused for any substantial amount of text.  A copy that is not\n\"Transparent\" is called \"Opaque\".\n\nExamples of suitable formats for Transparent copies include plain\nASCII without markup, Texinfo input format, LaTeX input format,\nSGML or XML using a publicly available DTD, and standard-conforming\nsimple HTML, PostScript or PDF designed for human modification.\nExamples of transparent image formats include PNG, XCF and JPG.\nOpaque formats include proprietary formats that can be read and\nedited only by proprietary word processors, SGML or XML for which\nthe DTD and/or processing tools are not generally available, and\nthe machine-generated HTML, PostScript or PDF produced by some word\nprocessors for output purposes only.\n\nThe \"Title Page\" means, for a printed book, the title page itself,\nplus such following pages as are needed to hold, legibly, the\nmaterial this License requires to appear in the title page.  For\nworks in formats which do not have any title page as such, \"Title\nPage\" means the text near the most prominent appearance of the\nwork's title, preceding the beginning of the body of the text.\n\nThe \"publisher\" means any person or entity that distributes copies\nof the Document to the public.\n\nA section \"Entitled XYZ\" means a named subunit of the Document\nwhose title either is precisely XYZ or contains XYZ in parentheses\nfollowing text that translates XYZ in another language.  (Here XYZ\nstands for a specific section name mentioned below, such as\n\"Acknowledgements\", \"Dedications\", \"Endorsements\", or \"History\".)\nTo \"Preserve the Title\" of such a section when you modify the\nDocument means that it remains a section \"Entitled XYZ\" according\nto this definition.\n\nThe Document may include Warranty Disclaimers next to the notice\nwhich states that this License applies to the Document.  These\nWarranty Disclaimers are considered to be included by reference in\nthis License, but only as regards disclaiming warranties: any other\nimplication that these Warranty Disclaimers may have is void and\nhas no effect on the meaning of this License.\n\n2. VERBATIM COPYING\n\nYou may copy and distribute the Document in any medium, either\ncommercially or noncommercially, provided that this License, the\ncopyright notices, and the license notice saying this License\napplies to the Document are reproduced in all copies, and that you\nadd no other conditions whatsoever to those of this License.  You\nmay not use technical measures to obstruct or control the reading\nor further copying of the copies you make or distribute.  However,\nyou may accept compensation in exchange for copies.  If you\ndistribute a large enough number of copies you must also follow the\nconditions in section 3.\n\nYou may also lend copies, under the same conditions stated above,\nand you may publicly display copies.\n\n3. COPYING IN QUANTITY\n\nIf you publish printed copies (or copies in media that commonly\nhave printed covers) of the Document, numbering more than 100, and\nthe Document's license notice requires Cover Texts, you must\nenclose the copies in covers that carry, clearly and legibly, all\nthese Cover Texts: Front-Cover Texts on the front cover, and\nBack-Cover Texts on the back cover.  Both covers must also clearly\nand legibly identify you as the publisher of these copies.  The\nfront cover must present the full title with all words of the title\nequally prominent and visible.  You may add other material on the\ncovers in addition.  Copying with changes limited to the covers, as\nlong as they preserve the title of the Document and satisfy these\nconditions, can be treated as verbatim copying in other respects.\n\nIf the required texts for either cover are too voluminous to fit\nlegibly, you should put the first ones listed (as many as fit\nreasonably) on the actual cover, and continue the rest onto\nadjacent pages.\n\nIf you publish or distribute Opaque copies of the Document\nnumbering more than 100, you must either include a machine-readable\nTransparent copy along with each Opaque copy, or state in or with\neach Opaque copy a computer-network location from which the general\nnetwork-using public has access to download using public-standard\nnetwork protocols a complete Transparent copy of the Document, free\nof added material.  If you use the latter option, you must take\nreasonably prudent steps, when you begin distribution of Opaque\ncopies in quantity, to ensure that this Transparent copy will\nremain thus accessible at the stated location until at least one\nyear after the last time you distribute an Opaque copy (directly or\nthrough your agents or retailers) of that edition to the public.\n\nIt is requested, but not required, that you contact the authors of\nthe Document well before redistributing any large number of copies,\nto give them a chance to provide you with an updated version of the\nDocument.\n\n4. MODIFICATIONS\n\nYou may copy and distribute a Modified Version of the Document\nunder the conditions of sections 2 and 3 above, provided that you\nrelease the Modified Version under precisely this License, with the\nModified Version filling the role of the Document, thus licensing\ndistribution and modification of the Modified Version to whoever\npossesses a copy of it.  In addition, you must do these things in\nthe Modified Version:\n\nA. Use in the Title Page (and on the covers, if any) a title\ndistinct from that of the Document, and from those of previous\nversions (which should, if there were any, be listed in the\nHistory section of the Document).  You may use the same title\nas a previous version if the original publisher of that\nversion gives permission.\n\nB. List on the Title Page, as authors, one or more persons or\nentities responsible for authorship of the modifications in\nthe Modified Version, together with at least five of the\nprincipal authors of the Document (all of its principal\nauthors, if it has fewer than five), unless they release you\nfrom this requirement.\n\nC. State on the Title page the name of the publisher of the\nModified Version, as the publisher.\n\nD. Preserve all the copyright notices of the Document.\n\nE. Add an appropriate copyright notice for your modifications\nadjacent to the other copyright notices.\n\nF. Include, immediately after the copyright notices, a license\nnotice giving the public permission to use the Modified\nVersion under the terms of this License, in the form shown in\nthe Addendum below.\n\nG. Preserve in that license notice the full lists of Invariant\nSections and required Cover Texts given in the Document's\nlicense notice.\n\nH. Include an unaltered copy of this License.\n\nI. Preserve the section Entitled \"History\", Preserve its Title,\nand add to it an item stating at least the title, year, new\nauthors, and publisher of the Modified Version as given on the\nTitle Page.  If there is no section Entitled \"History\" in the\nDocument, create one stating the title, year, authors, and\npublisher of the Document as given on its Title Page, then add\nan item describing the Modified Version as stated in the\nprevious sentence.\n\nJ. Preserve the network location, if any, given in the Document\nfor public access to a Transparent copy of the Document, and\nlikewise the network locations given in the Document for\nprevious versions it was based on.  These may be placed in the\n\"History\" section.  You may omit a network location for a work\nthat was published at least four years before the Document\nitself, or if the original publisher of the version it refers\nto gives permission.\n\nK. For any section Entitled \"Acknowledgements\" or \"Dedications\",\nPreserve the Title of the section, and preserve in the section\nall the substance and tone of each of the contributor\nacknowledgements and/or dedications given therein.\n\nL. Preserve all the Invariant Sections of the Document, unaltered\nin their text and in their titles.  Section numbers or the\nequivalent are not considered part of the section titles.\n\nM. Delete any section Entitled \"Endorsements\".  Such a section\nmay not be included in the Modified Version.\n\nN. Do not retitle any existing section to be Entitled\n\"Endorsements\" or to conflict in title with any Invariant\nSection.\n\nO. Preserve any Warranty Disclaimers.\n\nIf the Modified Version includes new front-matter sections or\nappendices that qualify as Secondary Sections and contain no\nmaterial copied from the Document, you may at your option designate\nsome or all of these sections as invariant.  To do this, add their\ntitles to the list of Invariant Sections in the Modified Version's\nlicense notice.  These titles must be distinct from any other\nsection titles.\n\nYou may add a section Entitled \"Endorsements\", provided it contains\nnothing but endorsements of your Modified Version by various\nparties--for example, statements of peer review or that the text\nhas been approved by an organization as the authoritative\ndefinition of a standard.\n\nYou may add a passage of up to five words as a Front-Cover Text,\nand a passage of up to 25 words as a Back-Cover Text, to the end of\nthe list of Cover Texts in the Modified Version.  Only one passage\nof Front-Cover Text and one of Back-Cover Text may be added by (or\nthrough arrangements made by) any one entity.  If the Document\nalready includes a cover text for the same cover, previously added\nby you or by arrangement made by the same entity you are acting on\nbehalf of, you may not add another; but you may replace the old\none, on explicit permission from the previous publisher that added\nthe old one.\n\nThe author(s) and publisher(s) of the Document do not by this\nLicense give permission to use their names for publicity for or to\nassert or imply endorsement of any Modified Version.\n\n5. COMBINING DOCUMENTS\n\nYou may combine the Document with other documents released under\nthis License, under the terms defined in section 4 above for\nmodified versions, provided that you include in the combination all\nof the Invariant Sections of all of the original documents,\nunmodified, and list them all as Invariant Sections of your\ncombined work in its license notice, and that you preserve all\ntheir Warranty Disclaimers.\n\nThe combined work need only contain one copy of this License, and\nmultiple identical Invariant Sections may be replaced with a single\ncopy.  If there are multiple Invariant Sections with the same name\nbut different contents, make the title of each such section unique\nby adding at the end of it, in parentheses, the name of the\noriginal author or publisher of that section if known, or else a\nunique number.  Make the same adjustment to the section titles in\nthe list of Invariant Sections in the license notice of the\ncombined work.\n\nIn the combination, you must combine any sections Entitled\n\"History\" in the various original documents, forming one section\nEntitled \"History\"; likewise combine any sections Entitled\n\"Acknowledgements\", and any sections Entitled \"Dedications\".  You\nmust delete all sections Entitled \"Endorsements.\"\n\n6. COLLECTIONS OF DOCUMENTS\n\nYou may make a collection consisting of the Document and other\ndocuments released under this License, and replace the individual\ncopies of this License in the various documents with a single copy\nthat is included in the collection, provided that you follow the\nrules of this License for verbatim copying of each of the documents\nin all other respects.\n\nYou may extract a single document from such a collection, and\ndistribute it individually under this License, provided you insert\na copy of this License into the extracted document, and follow this\nLicense in all other respects regarding verbatim copying of that\ndocument.\n\n7. AGGREGATION WITH INDEPENDENT WORKS\n\nA compilation of the Document or its derivatives with other\nseparate and independent documents or works, in or on a volume of a\nstorage or distribution medium, is called an \"aggregate\" if the\ncopyright resulting from the compilation is not used to limit the\nlegal rights of the compilation's users beyond what the individual\nworks permit.  When the Document is included in an aggregate, this\nLicense does not apply to the other works in the aggregate which\nare not themselves derivative works of the Document.\n\nIf the Cover Text requirement of section 3 is applicable to these\ncopies of the Document, then if the Document is less than one half\nof the entire aggregate, the Document's Cover Texts may be placed\non covers that bracket the Document within the aggregate, or the\nelectronic equivalent of covers if the Document is in electronic\nform.  Otherwise they must appear on printed covers that bracket\nthe whole aggregate.\n\n8. TRANSLATION\n\nTranslation is considered a kind of modification, so you may\ndistribute translations of the Document under the terms of section\n4.  Replacing Invariant Sections with translations requires special\npermission from their copyright holders, but you may include\ntranslations of some or all Invariant Sections in addition to the\noriginal versions of these Invariant Sections.  You may include a\ntranslation of this License, and all the license notices in the\nDocument, and any Warranty Disclaimers, provided that you also\ninclude the original English version of this License and the\noriginal versions of those notices and disclaimers.  In case of a\ndisagreement between the translation and the original version of\nthis License or a notice or disclaimer, the original version will\nprevail.\n\nIf a section in the Document is Entitled \"Acknowledgements\",\n\"Dedications\", or \"History\", the requirement (section 4) to\nPreserve its Title (section 1) will typically require changing the\nactual title.\n\n9. TERMINATION\n\nYou may not copy, modify, sublicense, or distribute the Document\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense, or distribute it is void,\nand will automatically terminate your rights under this License.\n\nHowever, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the\ncopyright holder fails to notify you of the violation by some\nreasonable means prior to 60 days after the cessation.\n\nMoreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from\nthat copyright holder, and you cure the violation prior to 30 days\nafter your receipt of the notice.\n\nTermination of your rights under this section does not terminate\nthe licenses of parties who have received copies or rights from you\nunder this License.  If your rights have been terminated and not\npermanently reinstated, receipt of a copy of some or all of the\nsame material does not give you any rights to use it.\n\n10. FUTURE REVISIONS OF THIS LICENSE\n\nThe Free Software Foundation may publish new, revised versions of\nthe GNU Free Documentation License from time to time.  Such new\nversions will be similar in spirit to the present version, but may\ndiffer in detail to address new problems or concerns.  See\n<https://www.gnu.org/copyleft/>.\n\nEach version of the License is given a distinguishing version\nnumber.  If the Document specifies that a particular numbered\nversion of this License \"or any later version\" applies to it, you\nhave the option of following the terms and conditions either of\nthat specified version or of any later version that has been\npublished (not as a draft) by the Free Software Foundation.  If the\nDocument does not specify a version number of this License, you may\nchoose any version ever published (not as a draft) by the Free\nSoftware Foundation.  If the Document specifies that a proxy can\ndecide which future versions of this License can be used, that\nproxy's public statement of acceptance of a version permanently\nauthorizes you to choose that version for the Document.\n\n11. RELICENSING\n\n\"Massive Multiauthor Collaboration Site\" (or \"MMC Site\") means any\nWorld Wide Web server that publishes copyrightable works and also\nprovides prominent facilities for anybody to edit those works.  A\npublic wiki that anybody can edit is an example of such a server.\nA \"Massive Multiauthor Collaboration\" (or \"MMC\") contained in the\nsite means any set of copyrightable works thus published on the MMC\nsite.\n\n\"CC-BY-SA\" means the Creative Commons Attribution-Share Alike 3.0\nlicense published by Creative Commons Corporation, a not-for-profit\ncorporation with a principal place of business in San Francisco,\nCalifornia, as well as future copyleft versions of that license\npublished by that same organization.\n\n\"Incorporate\" means to publish or republish a Document, in whole or\nin part, as part of another Document.\n\nAn MMC is \"eligible for relicensing\" if it is licensed under this\nLicense, and if all works that were first published under this\nLicense somewhere other than this MMC, and subsequently\nincorporated in whole or in part into the MMC, (1) had no cover\ntexts or invariant sections, and (2) were thus incorporated prior\nto November 1, 2008.\n\nThe operator of an MMC Site may republish an MMC contained in the\nsite under CC-BY-SA on the same site at any time before August 1,\n2009, provided the MMC is eligible for relicensing.\n",
            "subsections": [
                {
                    "name": "ADDENDUM: How to use this License for your documents",
                    "content": "To use this License in a document you have written, include a copy of\nthe License in the document and put the following copyright and license\nnotices just after the title page:\n\nCopyright (C)  YEAR  YOUR NAME.\nPermission is granted to copy, distribute and/or modify this document\nunder the terms of the GNU Free Documentation License, Version 1.3\nor any later version published by the Free Software Foundation;\nwith no Invariant Sections, no Front-Cover Texts, and no Back-Cover\nTexts.  A copy of the license is included in the section entitled ``GNU\nFree Documentation License''.\n\nIf you have Invariant Sections, Front-Cover Texts and Back-Cover\nTexts, replace the \"with...Texts.\" line with this:\n\nwith the Invariant Sections being LIST THEIR TITLES, with\nthe Front-Cover Texts being LIST, and with the Back-Cover Texts\nbeing LIST.\n\nIf you have Invariant Sections without Cover Texts, or some other\ncombination of the three, merge those two alternatives to suit the\nsituation.\n\nIf your document contains nontrivial examples of program code, we\nrecommend releasing these examples in parallel under your choice of free\nsoftware license, such as the GNU General Public License, to permit\ntheir use in free software.\n\nFile: sed.info,  Node: Concept Index,  Next: Command and Option Index,  Prev: GNU Free Documentation License,  Up: Top\n"
                }
            ]
        },
        "Concept Index": {
            "content": "This is a general index of all issues discussed in this manual, with the\nexception of the 'sed' commands and command-line options.\n\n\n* Menu:\n\n* -e, example:                           Overview.            (line  43)\n* -e, example <1>:                       sed script overview. (line  37)\n* -expression, example:                  Overview.            (line  43)\n* -f, example:                           Overview.            (line  43)\n* -f, example <1>:                       sed script overview. (line  37)\n* -file, example:                        Overview.            (line  43)\n* -i, example:                           Overview.            (line  23)\n* -n, example:                           Overview.            (line  30)\n* -s, example:                           Overview.            (line  37)\n* 0 address:                             Reporting Bugs.      (line 114)\n* ;, command separator:                  sed script overview. (line  37)\n* a, and semicolons:                     sed script overview. (line  56)\n* Additional reading about sed:          Other Resources.     (line  13)\n* ADDR1,+N:                              Range Addresses.     (line  31)\n* ADDR1,~N:                              Range Addresses.     (line  31)\n* address range, example:                sed script overview. (line  23)\n* Address, as a regular expression:      Regexp Addresses.    (line  13)\n* Address, last line:                    Numeric Addresses.   (line  13)\n* Address, numeric:                      Numeric Addresses.   (line   8)\n* addresses, excluding:                  Addresses overview.  (line  31)\n* Addresses, in sed scripts:             Numeric Addresses.   (line   6)\n* addresses, negating:                   Addresses overview.  (line  31)\n* addresses, numeric:                    Addresses overview.  (line   6)\n* addresses, range:                      Addresses overview.  (line  24)\n* addresses, regular expression:         Addresses overview.  (line  18)\n* addresses, syntax:                     sed script overview. (line  13)\n* alphabetic characters:                 Character Classes and Bracket Expressions.\n(line  49)\n* alphanumeric characters:               Character Classes and Bracket Expressions.\n(line  44)\n* Append hold space to pattern space:    Other Commands.      (line 284)\n* Append next input line to pattern space: Other Commands.    (line 257)\n* Append pattern space to hold space:    Other Commands.      (line 276)\n* Appending text after a line:           Other Commands.      (line  45)\n* b, joining lines with:                 Branching and flow control.\n(line 150)\n* b, versus t:                           Branching and flow control.\n(line 150)\n* back-reference:                        Back-references and Subexpressions.\n(line   6)\n* Backreferences, in regular expressions: The \"s\" Command.    (line  18)\n* blank characters:                      Character Classes and Bracket Expressions.\n(line  54)\n* bracket expression:                    Character Classes and Bracket Expressions.\n(line   6)\n* Branch to a label, if s/// failed:     Extended Commands.   (line  63)\n* Branch to a label, if s/// succeeded:  Programming Commands.\n(line  22)\n* Branch to a label, unconditionally:    Programming Commands.\n(line  18)\n* branching and n, N:                    Branching and flow control.\n(line 105)\n* branching, infinite loop:              Branching and flow control.\n(line  95)\n* branching, joining lines:              Branching and flow control.\n(line 150)\n* Buffer spaces, pattern and hold:       Execution Cycle.     (line   6)\n* Bugs, reporting:                       Reporting Bugs.      (line   6)\n* c, and semicolons:                     sed script overview. (line  56)\n* case insensitive, regular expression:  Regexp Addresses.    (line  47)\n* Case-insensitive matching:             The \"s\" Command.     (line 117)\n* Caveat -- #n on first line:            Common Commands.     (line  20)\n* character class:                       Character Classes and Bracket Expressions.\n(line   6)\n* character classes:                     Character Classes and Bracket Expressions.\n(line  43)\n* classes of characters:                 Character Classes and Bracket Expressions.\n(line  43)\n* Command groups:                        Common Commands.     (line  91)\n* Comments, in scripts:                  Common Commands.     (line  12)\n* Conditional branch:                    Programming Commands.\n(line  22)\n* Conditional branch <1>:                Extended Commands.   (line  63)\n* control characters:                    Character Classes and Bracket Expressions.\n(line  57)\n* Copy hold space into pattern space:    Other Commands.      (line 280)\n* Copy pattern space into hold space:    Other Commands.      (line 272)\n* cycle, restarting:                     Branching and flow control.\n(line  75)\n* d, example:                            sed script overview. (line  23)\n* Delete first line from pattern space:  Other Commands.      (line 251)\n* digit characters:                      Character Classes and Bracket Expressions.\n(line  62)\n* Disabling autoprint, from command line: Command-Line Options.\n(line  23)\n* empty regular expression:              Regexp Addresses.    (line  22)\n* Emptying pattern space:                Extended Commands.   (line  85)\n* Emptying pattern space <1>:            Reporting Bugs.      (line 143)\n* Evaluate Bourne-shell commands:        Extended Commands.   (line  12)\n* Evaluate Bourne-shell commands, after substitution: The \"s\" Command.\n(line 108)\n* example, address range:                sed script overview. (line  23)\n* example, regular expression:           sed script overview. (line  28)\n* Exchange hold space with pattern space: Other Commands.     (line 288)\n* Excluding lines:                       Addresses overview.  (line  31)\n* exit status:                           Exit status.         (line   6)\n* exit status, example:                  Exit status.         (line  25)\n* Extended regular expressions, choosing: Command-Line Options.\n(line 135)\n* Extended regular expressions, syntax:  ERE syntax.          (line   6)\n* File name, printing:                   Extended Commands.   (line  30)\n* Files to be processed as input:        Command-Line Options.\n(line 181)\n* Flow of control in scripts:            Programming Commands.\n(line  11)\n* Global substitution:                   The \"s\" Command.     (line  74)\n* GNU extensions, /dev/stderr file:      The \"s\" Command.     (line 101)\n* GNU extensions, /dev/stderr file <1>:  Other Commands.      (line 240)\n* GNU extensions, /dev/stdin file:       Other Commands.      (line 227)\n* GNU extensions, /dev/stdin file <1>:   Extended Commands.   (line  53)\n* GNU extensions, /dev/stdout file:      Command-Line Options.\n(line 189)\n* GNU extensions, /dev/stdout file <1>:  The \"s\" Command.     (line 101)\n* GNU extensions, /dev/stdout file <2>:  Other Commands.      (line 240)\n* GNU extensions, 0 address:             Range Addresses.     (line  31)\n* GNU extensions, 0 address <1>:         Reporting Bugs.      (line 114)\n* GNU extensions, 0,ADDR2 addressing:    Range Addresses.     (line  31)\n* GNU extensions, ADDR1,+N addressing:   Range Addresses.     (line  31)\n* GNU extensions, ADDR1,~N addressing:   Range Addresses.     (line  31)\n* GNU extensions, branch if s/// failed: Extended Commands.   (line  63)\n* GNU extensions, case modifiers in s commands: The \"s\" Command.\n(line  29)\n* GNU extensions, checking for their presence: Extended Commands.\n(line  69)\n* GNU extensions, debug:                 Command-Line Options.\n(line  29)\n* GNU extensions, disabling:             Command-Line Options.\n(line 102)\n* GNU extensions, emptying pattern space: Extended Commands.  (line  85)\n* GNU extensions, emptying pattern space <1>: Reporting Bugs. (line 143)\n* GNU extensions, evaluating Bourne-shell commands: The \"s\" Command.\n(line 108)\n* GNU extensions, evaluating Bourne-shell commands <1>: Extended Commands.\n(line  12)\n* GNU extensions, extended regular expressions: Command-Line Options.\n(line 135)\n* GNU extensions, g and NUMBER modifier: The \"s\" Command.     (line  80)\n* GNU extensions, I modifier:            The \"s\" Command.     (line 117)\n* GNU extensions, I modifier <1>:        Regexp Addresses.    (line  47)\n* GNU extensions, in-place editing:      Command-Line Options.\n(line  56)\n* GNU extensions, in-place editing <1>:  Reporting Bugs.      (line  95)\n* GNU extensions, M modifier:            The \"s\" Command.     (line 122)\n* GNU extensions, M modifier <1>:        Regexp Addresses.    (line  75)\n* GNU extensions, modifiers and the empty regular expression: Regexp Addresses.\n(line  22)\n* GNU extensions, N~M addresses:         Numeric Addresses.   (line  18)\n* GNU extensions, quitting silently:     Extended Commands.   (line  36)\n* GNU extensions, R command:             Extended Commands.   (line  53)\n* GNU extensions, reading a file a line at a time: Extended Commands.\n(line  53)\n* GNU extensions, returning an exit code: Common Commands.    (line  28)\n* GNU extensions, returning an exit code <1>: Extended Commands.\n(line  36)\n* GNU extensions, setting line length:   Other Commands.      (line 207)\n* GNU extensions, special escapes:       Escapes.             (line   6)\n* GNU extensions, special escapes <1>:   Reporting Bugs.      (line  88)\n* GNU extensions, special two-address forms: Range Addresses. (line  31)\n* GNU extensions, subprocesses:          The \"s\" Command.     (line 108)\n* GNU extensions, subprocesses <1>:      Extended Commands.   (line  12)\n* GNU extensions, to basic regular expressions: BRE syntax.   (line  13)\n* GNU extensions, to basic regular expressions <1>: BRE syntax.\n(line  59)\n* GNU extensions, to basic regular expressions <2>: BRE syntax.\n(line  62)\n* GNU extensions, to basic regular expressions <3>: BRE syntax.\n(line  77)\n* GNU extensions, to basic regular expressions <4>: BRE syntax.\n(line  87)\n* GNU extensions, to basic regular expressions <5>: Reporting Bugs.\n(line  61)\n* GNU extensions, two addresses supported by most commands: Other Commands.\n(line  61)\n* GNU extensions, two addresses supported by most commands <1>: Other Commands.\n(line 115)\n* GNU extensions, two addresses supported by most commands <2>: Other Commands.\n(line 204)\n* GNU extensions, two addresses supported by most commands <3>: Other Commands.\n(line 236)\n* GNU extensions, unlimited line length: Limitations.         (line   6)\n* GNU extensions, writing first line to a file: Extended Commands.\n(line  80)\n* Goto, in scripts:                      Programming Commands.\n(line  18)\n* graphic characters:                    Character Classes and Bracket Expressions.\n(line  65)\n* Greedy regular expression matching:    BRE syntax.          (line 113)\n* Grouping commands:                     Common Commands.     (line  91)\n* hexadecimal digits:                    Character Classes and Bracket Expressions.\n(line  88)\n* Hold space, appending from pattern space: Other Commands.   (line 276)\n* Hold space, appending to pattern space: Other Commands.     (line 284)\n* Hold space, copy into pattern space:   Other Commands.      (line 280)\n* Hold space, copying pattern space into: Other Commands.     (line 272)\n* Hold space, definition:                Execution Cycle.     (line   6)\n* Hold space, exchange with pattern space: Other Commands.    (line 288)\n* i, and semicolons:                     sed script overview. (line  56)\n* In-place editing:                      Reporting Bugs.      (line  95)\n* In-place editing, activating:          Command-Line Options.\n(line  56)\n* In-place editing, Perl-style backup file names: Command-Line Options.\n(line  67)\n* infinite loop, branching:              Branching and flow control.\n(line  95)\n* Inserting text before a line:          Other Commands.      (line 104)\n* joining lines with branching:          Branching and flow control.\n(line 150)\n* joining quoted-printable lines:        Branching and flow control.\n(line 150)\n* labels:                                Branching and flow control.\n(line  75)\n* Labels, in scripts:                    Programming Commands.\n(line  14)\n* Last line, selecting:                  Numeric Addresses.   (line  13)\n* Line length, setting:                  Command-Line Options.\n(line  97)\n* Line length, setting <1>:              Other Commands.      (line 207)\n* Line number, printing:                 Other Commands.      (line 194)\n* Line selection:                        Numeric Addresses.   (line   6)\n* Line, selecting by number:             Numeric Addresses.   (line   8)\n* Line, selecting by regular expression match: Regexp Addresses.\n(line  13)\n* Line, selecting last:                  Numeric Addresses.   (line  13)\n* List pattern space:                    Other Commands.      (line 207)\n* lower-case letters:                    Character Classes and Bracket Expressions.\n(line  68)\n* Mixing g and NUMBER modifiers in the s command: The \"s\" Command.\n(line  80)\n* multiple files:                        Overview.            (line  37)\n* multiple sed commands:                 sed script overview. (line  37)\n* n, and branching:                      Branching and flow control.\n(line 105)\n* N, and branching:                      Branching and flow control.\n(line 105)\n* named character classes:               Character Classes and Bracket Expressions.\n(line  43)\n* newline, command separator:            sed script overview. (line  37)\n* Next input line, append to pattern space: Other Commands.   (line 257)\n* Next input line, replace pattern space with: Common Commands.\n(line  61)\n* Non-bugs, 0 address:                   Reporting Bugs.      (line 114)\n* Non-bugs, in-place editing:            Reporting Bugs.      (line  95)\n* Non-bugs, localization-related:        Reporting Bugs.      (line 124)\n* Non-bugs, localization-related <1>:    Reporting Bugs.      (line 143)\n* Non-bugs, N command on the last line:  Reporting Bugs.      (line  30)\n* Non-bugs, regex syntax clashes:        Reporting Bugs.      (line  61)\n* numeric addresses:                     Addresses overview.  (line   6)\n* numeric characters:                    Character Classes and Bracket Expressions.\n(line  62)\n* omitting labels:                       Branching and flow control.\n(line  75)\n* output:                                Overview.            (line  23)\n* output, suppressing:                   Overview.            (line  30)\n* p, example:                            Overview.            (line  30)\n* paragraphs, processing:                Multiline techniques.\n(line  53)\n* parameters, script:                    Overview.            (line  43)\n* Parenthesized substrings:              The \"s\" Command.     (line  18)\n* Pattern space, definition:             Execution Cycle.     (line   6)\n* Portability, comments:                 Common Commands.     (line  15)\n* Portability, line length limitations:  Limitations.         (line   6)\n* Portability, N command on the last line: Reporting Bugs.    (line  30)\n* POSIXLYCORRECT behavior, bracket expressions: Character Classes and Bracket Expressions.\n(line 112)\n* POSIXLYCORRECT behavior, enabling:    Command-Line Options.\n(line 105)\n* POSIXLYCORRECT behavior, escapes:     Escapes.             (line  11)\n* POSIXLYCORRECT behavior, N command:   Reporting Bugs.      (line  56)\n* Print first line from pattern space:   Other Commands.      (line 269)\n* printable characters:                  Character Classes and Bracket Expressions.\n(line  72)\n* Printing file name:                    Extended Commands.   (line  30)\n* Printing line number:                  Other Commands.      (line 194)\n* Printing text unambiguously:           Other Commands.      (line 207)\n* processing paragraphs:                 Multiline techniques.\n(line  53)\n* punctuation characters:                Character Classes and Bracket Expressions.\n(line  75)\n* Q, example:                            Exit status.         (line  25)\n* q, example:                            sed script overview. (line  28)\n* Quitting:                              Common Commands.     (line  28)\n* Quitting <1>:                          Extended Commands.   (line  36)\n* quoted-printable lines, joining:       Branching and flow control.\n(line 150)\n* range addresses:                       Addresses overview.  (line  24)\n* range expression:                      Character Classes and Bracket Expressions.\n(line  18)\n* Range of lines:                        Range Addresses.     (line   6)\n* Range with start address of zero:      Range Addresses.     (line  31)\n* Read next input line:                  Common Commands.     (line  61)\n* Read text from a file:                 Other Commands.      (line 219)\n* Read text from a file <1>:             Extended Commands.   (line  53)\n* regex addresses and input lines:       Regexp Addresses.    (line  84)\n* regex addresses and pattern space:     Regexp Addresses.    (line  84)\n* regular expression addresses:          Addresses overview.  (line  18)\n* regular expression, example:           sed script overview. (line  28)\n* Replace hold space with copy of pattern space: Other Commands.\n(line 272)\n* Replace pattern space with copy of hold space: Other Commands.\n(line 280)\n* Replacing all text matching regexp in a line: The \"s\" Command.\n(line  74)\n* Replacing only Nth match of regexp in a line: The \"s\" Command.\n(line  78)\n* Replacing selected lines with other text: Other Commands.   (line 157)\n* Requiring GNU sed:                     Extended Commands.   (line  69)\n* restarting a cycle:                    Branching and flow control.\n(line  75)\n* Sandbox mode:                          Command-Line Options.\n(line 157)\n* script parameter:                      Overview.            (line  43)\n* Script structure:                      sed script overview. (line   6)\n* Script, from a file:                   Command-Line Options.\n(line  51)\n* Script, from command line:             Command-Line Options.\n(line  46)\n* sed commands syntax:                   sed script overview. (line  13)\n* sed commands, multiple:                sed script overview. (line  37)\n* sed script structure:                  sed script overview. (line   6)\n* Selecting lines to process:            Numeric Addresses.   (line   6)\n* Selecting non-matching lines:          Addresses overview.  (line  31)\n* semicolons, command separator:         sed script overview. (line  37)\n* Several lines, selecting:              Range Addresses.     (line   6)\n* Slash character, in regular expressions: Regexp Addresses.  (line  32)\n* space characters:                      Character Classes and Bracket Expressions.\n(line  80)\n* Spaces, pattern and hold:              Execution Cycle.     (line   6)\n* Special addressing forms:              Range Addresses.     (line  31)\n* standard input:                        Overview.            (line  15)\n* Standard input, processing as input:   Command-Line Options.\n(line 183)\n* standard output:                       Overview.            (line  23)\n* stdin:                                 Overview.            (line  15)\n* stdout:                                Overview.            (line  23)\n* Stream editor:                         Introduction.        (line   6)\n* subexpression:                         Back-references and Subexpressions.\n(line   6)\n* Subprocesses:                          The \"s\" Command.     (line 108)\n* Subprocesses <1>:                      Extended Commands.   (line  12)\n* Substitution of text, options:         The \"s\" Command.     (line  70)\n* suppressing output:                    Overview.            (line  30)\n* syntax, addresses:                     sed script overview. (line  13)\n* syntax, sed commands:                  sed script overview. (line  13)\n* t, joining lines with:                 Branching and flow control.\n(line 150)\n* t, versus b:                           Branching and flow control.\n(line 150)\n* Text, appending:                       Other Commands.      (line  45)\n* Text, deleting:                        Common Commands.     (line  44)\n* Text, insertion:                       Other Commands.      (line 104)\n* Text, printing:                        Common Commands.     (line  52)\n* Text, printing after substitution:     The \"s\" Command.     (line  88)\n* Text, writing to a file after substitution: The \"s\" Command.\n(line 101)\n* Transliteration:                       Other Commands.      (line  11)\n* Unbuffered I/O, choosing:              Command-Line Options.\n(line 164)\n* upper-case letters:                    Character Classes and Bracket Expressions.\n(line  84)\n* Usage summary, printing:               Command-Line Options.\n(line  17)\n* Version, printing:                     Command-Line Options.\n(line  13)\n* whitespace characters:                 Character Classes and Bracket Expressions.\n(line  80)\n* Working on separate files:             Command-Line Options.\n(line 148)\n* Write first line to a file:            Extended Commands.   (line  80)\n* Write to a file:                       Other Commands.      (line 240)\n* xdigit class:                          Character Classes and Bracket Expressions.\n(line  88)\n* Zero, as range start address:          Range Addresses.     (line  31)\n\nFile: sed.info,  Node: Command and Option Index,  Prev: Concept Index,  Up: Top\n",
            "subsections": []
        },
        "Command and Option Index": {
            "content": "This is an alphabetical list of all 'sed' commands and command-line\noptions.\n\n\n* Menu:\n\n* # (comments):                          Common Commands.     (line  12)\n* --binary:                              Command-Line Options.\n(line 114)\n* --debug:                               Command-Line Options.\n(line  29)\n* --expression:                          Command-Line Options.\n(line  46)\n* --file:                                Command-Line Options.\n(line  51)\n* --follow-symlinks:                     Command-Line Options.\n(line 125)\n* --help:                                Command-Line Options.\n(line  17)\n* --in-place:                            Command-Line Options.\n(line  56)\n* --line-length:                         Command-Line Options.\n(line  97)\n* --null-data:                           Command-Line Options.\n(line 172)\n* --posix:                               Command-Line Options.\n(line 102)\n* --quiet:                               Command-Line Options.\n(line  23)\n* --regexp-extended:                     Command-Line Options.\n(line 135)\n* --sandbox:                             Command-Line Options.\n(line 157)\n* --separate:                            Command-Line Options.\n(line 148)\n* --silent:                              Command-Line Options.\n(line  23)\n* --unbuffered:                          Command-Line Options.\n(line 164)\n* --version:                             Command-Line Options.\n(line  13)\n* --zero-terminated:                     Command-Line Options.\n(line 172)\n* -b:                                    Command-Line Options.\n(line 114)\n* -e:                                    Command-Line Options.\n(line  46)\n* -E:                                    Command-Line Options.\n(line 135)\n* -f:                                    Command-Line Options.\n(line  51)\n* -i:                                    Command-Line Options.\n(line  56)\n* -l:                                    Command-Line Options.\n(line  97)\n* -n:                                    Command-Line Options.\n(line  23)\n* -n, forcing from within a script:      Common Commands.     (line  20)\n* -r:                                    Command-Line Options.\n(line 135)\n* -s:                                    Command-Line Options.\n(line 148)\n* -u:                                    Command-Line Options.\n(line 164)\n* -z:                                    Command-Line Options.\n(line 172)\n* : (label) command:                     Programming Commands.\n(line  14)\n* = (print line number) command:         Other Commands.      (line 194)\n* {} command grouping:                   Common Commands.     (line  91)\n* a (append text lines) command:         Other Commands.      (line  45)\n* alnum character class:                 Character Classes and Bracket Expressions.\n(line  44)\n* alpha character class:                 Character Classes and Bracket Expressions.\n(line  49)\n* b (branch) command:                    Programming Commands.\n(line  18)\n* blank character class:                 Character Classes and Bracket Expressions.\n(line  54)\n* c (change to text lines) command:      Other Commands.      (line 157)\n* cntrl character class:                 Character Classes and Bracket Expressions.\n(line  57)\n* D (delete first line) command:         Other Commands.      (line 251)\n* d (delete) command:                    Common Commands.     (line  44)\n* digit character class:                 Character Classes and Bracket Expressions.\n(line  62)\n* e (evaluate) command:                  Extended Commands.   (line  12)\n* F (File name) command:                 Extended Commands.   (line  30)\n* G (appending Get) command:             Other Commands.      (line 284)\n* g (get) command:                       Other Commands.      (line 280)\n* graph character class:                 Character Classes and Bracket Expressions.\n(line  65)\n* H (append Hold) command:               Other Commands.      (line 276)\n* h (hold) command:                      Other Commands.      (line 272)\n* i (insert text lines) command:         Other Commands.      (line 104)\n* l (list unambiguously) command:        Other Commands.      (line 207)\n* lower character class:                 Character Classes and Bracket Expressions.\n(line  68)\n* N (append Next line) command:          Other Commands.      (line 257)\n* n (next-line) command:                 Common Commands.     (line  61)\n* P (print first line) command:          Other Commands.      (line 269)\n* p (print) command:                     Common Commands.     (line  52)\n* print character class:                 Character Classes and Bracket Expressions.\n(line  72)\n* punct character class:                 Character Classes and Bracket Expressions.\n(line  75)\n* q (quit) command:                      Common Commands.     (line  28)\n* Q (silent Quit) command:               Extended Commands.   (line  36)\n* r (read file) command:                 Other Commands.      (line 219)\n* R (read line) command:                 Extended Commands.   (line  53)\n* s command, option flags:               The \"s\" Command.     (line  70)\n* space character class:                 Character Classes and Bracket Expressions.\n(line  80)\n* T (test and branch if failed) command: Extended Commands.   (line  63)\n* t (test and branch if successful) command: Programming Commands.\n(line  22)\n* upper character class:                 Character Classes and Bracket Expressions.\n(line  84)\n* v (version) command:                   Extended Commands.   (line  69)\n* w (write file) command:                Other Commands.      (line 240)\n* W (write first line) command:          Extended Commands.   (line  80)\n* x (eXchange) command:                  Other Commands.      (line 288)\n* xdigit character class:                Character Classes and Bracket Expressions.\n(line  88)\n* y (transliterate) command:             Other Commands.      (line  11)\n* z (Zap) command:                       Extended Commands.   (line  85)\n\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}