summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/local.mk15
-rw-r--r--doc/sed-dummy.117
-rw-r--r--doc/sed.14
-rw-r--r--doc/sed.info630
-rw-r--r--doc/sed.texi679
-rw-r--r--doc/stamp-vti8
-rw-r--r--doc/version.texi8
7 files changed, 1229 insertions, 132 deletions
diff --git a/doc/local.mk b/doc/local.mk
index 21d9344..3026c64 100644
--- a/doc/local.mk
+++ b/doc/local.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2016 Free Software Foundation, Inc.
+# Copyright (C) 2016-2017 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,12 +16,13 @@
info_TEXINFOS = doc/sed.texi
doc_sed_TEXINFOS = doc/config.texi doc/version.texi doc/fdl.texi
dist_man_MANS = doc/sed.1
-dist_noinst_DATA = doc/sed.x
+dist_noinst_DATA = doc/sed.x doc/sed-dummy.1
HELP2MAN = $(top_srcdir)/build-aux/help2man
SEDBIN = sed/sed
AM_MAKEINFOHTMLFLAGS = --no-split
+if BUILD_MAN_PAGE
doc/sed.1: sed/sed$(EXEEXT) .version $(srcdir)/doc/sed.x
$(AM_V_GEN)$(MKDIR_P) doc
$(AM_V_at)rm -rf $@ $@-t
@@ -31,3 +32,13 @@ doc/sed.1: sed/sed$(EXEEXT) .version $(srcdir)/doc/sed.x
-o $@-t $(SEDBIN) \
&& chmod a-w $@-t \
&& mv $@-t $@
+else !BUILD_MAN_PAGE
+
+if BUILD_DUMMY_MAN_PAGE
+doc/sed.1: doc/sed-dummy.1
+ $(AM_V_at)$(SED) 's/VERSION/$(PACKAGE_VERSION)/' $< > $@-t \
+ && chmod a-w $@-t \
+ && mv $@-t $@
+endif BUILD_DUMMY_MAN_PAGE
+
+endif !BUILD_MAN_PAGE
diff --git a/doc/sed-dummy.1 b/doc/sed-dummy.1
new file mode 100644
index 0000000..3832baf
--- /dev/null
+++ b/doc/sed-dummy.1
@@ -0,0 +1,17 @@
+.TH SED "1" "VERSION" "User Commands"
+.SH NAME
+sed \- stream editor for filtering and transforming text
+.SH SYNOPSIS
+.B sed
+[\fIOPTION\fR]... \fI{script-only-if-no-other-script} \fR[\fIinput-file\fR]...
+.SH DESCRIPTION
+.B OOOPS!
+.B sed
+manual page could not be built (missing perl or
+cross-compilation).
+.PP
+For the full documentation for
+.B sed
+see
+.UR http://www.gnu.org/software/sed
+GNU SED Website (http://www.gnu.org/software/sed)
diff --git a/doc/sed.1 b/doc/sed.1
index 3d71e44..2db3cdc 100644
--- a/doc/sed.1
+++ b/doc/sed.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
-.TH SED "1" "December 2016" "sed 4.3" "User Commands"
+.TH SED "1" "February 2017" "sed 4.4" "User Commands"
.SH NAME
sed \- stream editor for filtering and transforming text
.SH SYNOPSIS
@@ -387,7 +387,7 @@ GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
.SH COPYRIGHT
-Copyright \(co 2016 Free Software Foundation, Inc.
+Copyright \(co 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
.br
This is free software: you are free to change and redistribute it.
diff --git a/doc/sed.info b/doc/sed.info
index 6caa43c..92e42d4 100644
--- a/doc/sed.info
+++ b/doc/sed.info
@@ -1,8 +1,8 @@
This is sed.info-t, produced by makeinfo version 6.3 from sed.texi.
-This file documents version 4.3 of GNU 'sed', a stream editor.
+This file documents version 4.4 of GNU 'sed', a stream editor.
- Copyright (C) 1998-2016 Free Software Foundation, Inc.
+ Copyright (C) 1998-2017 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
@@ -22,9 +22,9 @@ File: sed.info-t, Node: Top, Next: Introduction, Up: (dir)
GNU 'sed'
*********
-This file documents version 4.3 of GNU 'sed', a stream editor.
+This file documents version 4.4 of GNU 'sed', a stream editor.
- Copyright (C) 1998-2016 Free Software Foundation, Inc.
+ Copyright (C) 1998-2017 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
@@ -348,6 +348,7 @@ File: sed.info-t, Node: sed scripts, Next: sed addresses, Prev: Invoking sed,
* Other Commands:: Less frequently used commands
* Programming Commands:: Commands for 'sed' gurus
* Extended Commands:: Commands specific of GNU 'sed'
+* Multiple commands syntax:: Extension for easier scripting

File: sed.info-t, Node: sed script overview, Next: sed commands list, Up: sed scripts
@@ -409,7 +410,7 @@ and replacing all occurrences of the string 'hello' with 'world':
semicolons working as command separators and thus should be terminated
with newlines or be placed at the end of a SCRIPT or SCRIPT-FILE.
Commands can also be preceded with optional non-significant whitespace
-characters.
+characters. *Note Multiple commands syntax::.

File: sed.info-t, Node: sed commands list, Next: The "s" Command, Prev: sed script overview, Up: sed scripts
@@ -675,10 +676,10 @@ FLAGS:
command show their effect just once. This behavior, although
documented, might change in future versions.
-'w FILE-NAME'
+'w FILENAME'
If the substitution was made, then write out the result to the
named file. As a GNU 'sed' extension, two special values of
- FILE-NAME are supported: '/dev/stderr', which writes the result to
+ FILENAME are supported: '/dev/stderr', which writes the result to
the standard error, and '/dev/stdout', which writes to the standard
output.(1)
@@ -849,7 +850,7 @@ commands.
hello
3
- Leading whitespaces after the 'a' command are ignored. The text to
+ Leading whitespace after the 'a' command is ignored. The text to
add is read until the end of the line.
'a\'
@@ -908,7 +909,7 @@ commands.
2
3
- Leading whitespaces after the 'i' command are ignored. The text to
+ Leading whitespace after the 'i' command is ignored. The text to
add is read until the end of the line.
'i\'
@@ -961,7 +962,7 @@ commands.
hello
10
- Leading whitespaces after the 'c' command are ignored. The text to
+ Leading whitespace after the 'c' command is ignored. The text to
add is read until the end of the line.
'c\'
@@ -1050,7 +1051,7 @@ commands.
'w FILENAME'
Write the pattern space to FILENAME. As a GNU 'sed' extension, two
- special values of FILE-NAME are supported: '/dev/stderr', which
+ special values of FILENAME are supported: '/dev/stderr', which
writes the result to the standard error, and '/dev/stdout', which
writes to the standard output.(1)
@@ -1130,7 +1131,7 @@ can enable one to write quite convoluted scripts.
The LABEL may be omitted, in which case the next cycle is started.

-File: sed.info-t, Node: Extended Commands, Prev: Programming Commands, Up: sed scripts
+File: sed.info-t, Node: Extended Commands, Next: Multiple commands syntax, Prev: Programming Commands, Up: sed scripts
3.7 Commands Specific to GNU 'sed'
==================================
@@ -1222,6 +1223,177 @@ required quite often, yet are unsupported by standard 'sed's.
the script in most multibyte locales (including UTF-8 locales).

+File: sed.info-t, Node: Multiple commands syntax, Prev: Extended Commands, Up: sed scripts
+
+3.8 Multiple commands syntax
+============================
+
+There are several methods to specify multiple commands in a 'sed'
+program.
+
+ Using newlines is most natural when running a sed script from a file
+(using the '-f' option).
+
+ On the command line, all 'sed' commands may be separated by newlines.
+Alternatively, you may specify each command as an argument to an '-e'
+option:
+
+ $ seq 6 | sed '1d
+ 3d
+ 5d'
+ 2
+ 4
+ 6
+
+ $ seq 6 | sed -e 1d -e 3d -e 5d
+ 2
+ 4
+ 6
+
+ A semicolon (';') may be used to separate most simple commands:
+
+ $ seq 6 | sed '1d;3d;5d'
+ 2
+ 4
+ 6
+
+ The '{','}','b','t','T',':' commands can be separated with a
+semicolon (this is a non-portable GNU 'sed' extension).
+
+ $ seq 4 | sed '{1d;3d}'
+ 2
+ 4
+
+ $ seq 6 | sed '{1d;3d};5d'
+ 2
+ 4
+ 6
+
+ Labels used in 'b','t','T',':' commands are read until a semicolon.
+Leading and trailing whitespace is ignored. In the examples below the
+label is 'x'. The first example works with GNU 'sed'. The second is a
+portable equivalent. For more information about branching and labels
+*note Branching and flow control::.
+
+ $ seq 3 | sed '/1/b x ; s/^/=/ ; :x ; 3d'
+ 1
+ =2
+
+ $ seq 3 | sed -e '/1/bx' -e 's/^/=/' -e ':x' -e '3d'
+ 1
+ =2
+
+3.8.1 Commands Requiring a newline
+----------------------------------
+
+The following commands cannot be separated by a semicolon and require a
+newline:
+
+'a','c','i' (append/change/insert)
+
+ All characters following 'a','c','i' commands are taken as the text
+ to append/change/insert. Using a semicolon leads to undesirable
+ results:
+
+ $ seq 2 | sed '1aHello ; 2d'
+ 1
+ Hello ; 2d
+ 2
+
+ Separate the commands using '-e' or a newline:
+
+ $ seq 2 | sed -e 1aHello -e 2d
+ 1
+ Hello
+
+ $ seq 2 | sed '1aHello
+ 2d'
+ 1
+ Hello
+
+ Note that specifying the text to add ('Hello') immediately after
+ 'a','c','i' is itself a GNU 'sed' extension. A portable,
+ POSIX-compliant alternative is:
+
+ $ seq 2 | sed '1a\
+ Hello
+ 2d'
+ 1
+ Hello
+
+'#' (comment)
+
+ All characters following '#' until the next newline are ignored.
+
+ $ seq 3 | sed '# this is a comment ; 2d'
+ 1
+ 2
+ 3
+
+
+ $ seq 3 | sed '# this is a comment
+ 2d'
+ 1
+ 3
+
+'r','R','w','W' (reading and writing files)
+
+ The 'r','R','w','W' commands parse the filename until end of the
+ line. If whitespace, comments or semicolons are found, they will
+ be included in the filename, leading to unexpected results:
+
+ $ seq 2 | sed '1w hello.txt ; 2d'
+ 1
+ 2
+
+ $ ls -log
+ total 4
+ -rw-rw-r-- 1 2 Jan 23 23:03 hello.txt ; 2d
+
+ $ cat 'hello.txt ; 2d'
+ 1
+
+ Note that 'sed' silently ignores read/write errors in
+ 'r','R','w','W' commands (such as missing files). In the following
+ example, 'sed' tries to read a file named ''hello.txt ; N''. The
+ file is missing, and the error is silently ignored:
+
+ $ echo x | sed '1rhello.txt ; N'
+ x
+
+'e' (command execution)
+
+ Any characters following the 'e' command until the end of the line
+ will be sent to the shell. If whitespace, comments or semicolons
+ are found, they will be included in the shell command, leading to
+ unexpected results:
+
+ $ echo a | sed '1e touch foo#bar'
+ a
+
+ $ ls -1
+ foo#bar
+
+ $ echo a | sed '1e touch foo ; s/a/b/'
+ sh: 1: s/a/b/: not found
+ a
+
+'s///[we]' (substitute with 'e' or 'w' flags)
+
+ In a substitution command, the 'w' flag writes the substitution
+ result to a file, and the 'e' flag executes the subsitution result
+ as a shell command. As with the 'r/R/w/W/e' commands, these must
+ be terminated with a newline. If whitespace, comments or
+ semicolons are found, they will be included in the shell command or
+ filename, leading to unexpected results:
+
+ $ echo a | sed 's/a/b/w1.txt#foo'
+ b
+
+ $ ls -1
+ 1.txt#foo
+
+
File: sed.info-t, Node: sed addresses, Next: sed regular expressions, Prev: sed scripts, Up: Top
4 Addresses: selecting lines
@@ -2290,7 +2462,7 @@ commands:
and the next line to the pattern space (i.e. '1', '\n', '2' in the
first cycle).
3. The 'l' command prints the content of the pattern space
- unambigiously.
+ unambiguously.
4. The 'D' command then removes the content of pattern space up to the
first newline (leaving '2' at the end of the first cycle).
5. At the next cycle the 'N' command appends a newline and the next
@@ -2355,7 +2527,207 @@ File: sed.info-t, Node: Branching and flow control, Prev: Multiline techniques
6.4 Branching and Flow Control
==============================
-TODO
+The branching commands 'b', 't', and 'T' enable changing the flow of
+'sed' programs.
+
+ By default, 'sed' reads an input line into the pattern buffer, then
+continues to processes all commands in order. Commands without
+addresses affect all lines. Commands with addresses affect only
+matching lines. *Note Execution Cycle:: and *note Addresses overview::.
+
+ 'sed' does not support a typical 'if/then' construct. Instead, some
+commands can be used as conditionals or to change the default flow
+control:
+
+'d'
+ delete (clears) the current pattern space, and restart the program
+ cycle without processing the rest of the commands and without
+ printing the pattern space.
+
+'D'
+ delete the contents of the pattern space _up to the first newline_,
+ and restart the program cycle without processing the rest of the
+ commands and without printing the pattern space.
+
+'[addr]X'
+'[addr]{ X ; X ; X }'
+'/regexp/X'
+'/regexp/{ X ; X ; X }'
+ Addresses and regular expressions can be used as an 'if/then'
+ conditional: If [ADDR] matches the current pattern space, execute
+ the command(s). For example: The command '/^#/d' means: _if_ the
+ current pattern matches the regular expression '^#' (a line
+ starting with a hash), _then_ execute the 'd' command: delete the
+ line without printing it, and restart the program cycle
+ immediately.
+
+'b'
+ branch unconditionally (that is: always jump to a label, skipping
+ or repeating other commands, without restarting a new cycle).
+ Combined with an address, the branch can be conditionally executed
+ on matched lines.
+
+'t'
+ branch conditionally (that is: jump to a label) _only if_ a 's///'
+ command has succeeded since the last input line was read or another
+ conditional branch was taken.
+
+'T'
+ similar but opposite to the 't' command: branch only if there has
+ been _no_ successful substitutions since the last input line was
+ read.
+
+ The following two 'sed' programs are equivalent. The first
+(contrived) example uses the 'b' command to skip the 's///' command on
+lines containing '1'. The second example uses an address with negation
+('!') to perform substitution only on desired lines. The 'y///' command
+is still executed on all lines:
+
+ $ printf '%s\n' a1 a2 a3 | sed -E '/1/bx ; s/a/z/ ; :x ; y/123/456/'
+ a4
+ z5
+ z6
+
+ $ printf '%s\n' a1 a2 a3 | sed -E '/1/!s/a/z/ ; y/123/456/'
+ a4
+ z5
+ z6
+
+6.4.1 Branching and Cycles
+--------------------------
+
+The 'b','t' and 'T' commands can be followed by a label (typically a
+single letter). Labels are defined with a colon followed by one or more
+letters (e.g. ':x'). If the label is omitted the branch commands
+restart the cycle. Note the difference between branching to a label and
+restarting the cycle: when a cycle is restarted, 'sed' first prints the
+current content of the pattern space, then reads the next input line
+into the pattern space; Jumping to a label (even if it is at the
+beginning of the program) does not print the pattern space and does not
+read the next input line.
+
+ The following program is a no-op. The 'b' command (the only command
+in the program) does not have a label, and thus simply restarts the
+cycle. On each cycle, the pattern space is printed and the next input
+line is read:
+
+ $ seq 3 | sed b
+ 1
+ 2
+ 3
+
+ The following example is an infinite-loop - it doesn't terminate and
+doesn't print anything. The 'b' command jumps to the 'x' label, and a
+new cycle is never started:
+
+ $ seq 3 | sed ':x ; bx'
+
+ # The above command requires gnu sed (which supports additional
+ # commands following a label, without a newline). A portable equivalent:
+ # sed -e ':x' -e bx
+
+ Branching is often complemented with the 'n' or 'N' commands: both
+commands read the next input line into the pattern space without waiting
+for the cycle to restart. Before reading the next input line, 'n'
+prints the current pattern space then empties it, while 'N' appends a
+newline and the next input line to the pattern space.
+
+ Consider the following two examples:
+
+ $ seq 3 | sed ':x ; n ; bx'
+ 1
+ 2
+ 3
+
+ $ seq 3 | sed ':x ; N ; bx'
+ 1
+ 2
+ 3
+
+ * Both examples do not inf-loop, despite never starting a new cycle.
+
+ * In the first example, the 'n' commands first prints the content of
+ the pattern space, empties the pattern space then reads the next
+ input line.
+
+ * In the second example, the 'N' commands appends the next input line
+ to the pattern space (with a newline). Lines are accumulated in
+ the pattern space until there are no more input lines to read, then
+ the 'N' command terminates the 'sed' program. When the program
+ terminates, the end-of-cycle actions are performed, and the entire
+ pattern space is printed.
+
+ * The second example requires GNU 'sed', because it uses the
+ non-POSIX-standard behavior of 'N'. See the "'N' command on the
+ last line" paragraph in *note Reporting Bugs::.
+
+ * To further examine the difference between the two examples, try the
+ following commands:
+ printf '%s\n' aa bb cc dd | sed ':x ; n ; = ; bx'
+ printf '%s\n' aa bb cc dd | sed ':x ; N ; = ; bx'
+ printf '%s\n' aa bb cc dd | sed ':x ; n ; s/\n/***/ ; bx'
+ printf '%s\n' aa bb cc dd | sed ':x ; N ; s/\n/***/ ; bx'
+
+6.4.2 Branching example: joining lines
+--------------------------------------
+
+As a real-world example of using branching, consider the case of
+quoted-printable (https://en.wikipedia.org/wiki/Quoted-printable) files,
+typically used to encode email messages. In these files long lines are
+split and marked with a "soft line break" consisting of a single '='
+character at the end of the line:
+
+ $ cat jaques.txt
+ All the wor=
+ ld's a stag=
+ e,
+ And all the=
+ men and wo=
+ men merely =
+ players:
+ They have t=
+ heir exits =
+ and their e=
+ ntrances;
+ And one man=
+ in his tim=
+ e plays man=
+ y parts.
+
+ The following program uses an address match '/=$/' as a conditional:
+If the current pattern space ends with a '=', it reads the next input
+line using 'N', replaces all '=' characters which are followed by a
+newline, and unconditionally branches ('b') to the beginning of the
+program without restarting a new cycle. If the pattern space does not
+ends with '=', the default action is performed: the pattern space is
+printed and a new cycle is started:
+
+ $ sed ':x ; /=$/ { N ; s/=\n//g ; bx }' jaques.txt
+ All the world's a stage,
+ And all the men and women merely players:
+ They have their exits and their entrances;
+ And one man in his time plays many parts.
+
+ Here's an alternative program with a slightly different approach: On
+all lines except the last, 'N' appends the line to the pattern space. A
+substitution command then removes soft line breaks ('=' at the end of a
+line, i.e. followed by a newline) by replacing them with an empty
+string. _if_ the substitution was successful (meaning the pattern space
+contained a line which should be joined), The conditional branch command
+'t' jumps to the beginning of the program without completing or
+restarting the cycle. If the substitution failed (meaning there were no
+soft line breaks), The 't' command will _not_ branch. Then, 'P' will
+print the pattern space content until the first newline, and 'D' will
+delete the pattern space content until the first new line. (To learn
+more about 'N', 'P' and 'D' commands *note Multiline techniques::).
+
+ $ sed ':x ; $!N ; s/=\n// ; tx ; P ; D' jaques.txt
+ All the world's a stage,
+ And all the men and women merely players:
+ They have their exits and their entrances;
+ And one man in his time plays many parts.
+
+ For more line-joining examples *note Joining lines::.

File: sed.info-t, Node: Examples, Next: Limitations, Prev: advanced sed, Up: Top
@@ -2400,7 +2772,11 @@ File: sed.info-t, Node: Joining lines, Next: Centering lines, Up: Examples
7.1 Joining lines
=================
-Join specific lines (e.g. if lines 2 and 3 need to be joined):
+This section uses 'N', 'D' and 'P' commands to process multiple lines,
+and the 'b' and 't' commands for branching. *Note Multiline
+techniques:: and *note Branching and flow control::.
+
+ Join specific lines (e.g. if lines 2 and 3 need to be joined):
$ cat lines.txt
hello
@@ -2413,7 +2789,7 @@ Join specific lines (e.g. if lines 2 and 3 need to be joined):
hello
hello
- Join lines ending with backslashes:
+ Join backslash-continued lines:
$ cat 1.txt
this \
@@ -2432,6 +2808,33 @@ Join specific lines (e.g. if lines 2 and 3 need to be joined):
#TODO: The above requires gnu sed.
# non-gnu seds need newlines after ':' and 'b'
+ Join lines that start with whitespace (e.g SMTP headers):
+
+ $ cat 2.txt
+ Subject: Hello
+ World
+ Content-Type: multipart/alternative;
+ boundary=94eb2c190cc6370f06054535da6a
+ Date: Tue, 3 Jan 2017 19:41:16 +0000 (GMT)
+ Authentication-Results: mx.gnu.org;
+ dkim=pass header.i=@gnu.org;
+ spf=pass
+ Message-ID: <abcdef@gnu.org>
+ From: John Doe <jdoe@gnu.org>
+ To: Jane Smith <jsmith@gnu.org>
+
+ $ sed -E ':a ; $!N ; s/\n\s+/ / ; ta ; P ; D' 2.txt
+ Subject: Hello World
+ Content-Type: multipart/alternative; boundary=94eb2c190cc6370f06054535da6a
+ Date: Tue, 3 Jan 2017 19:41:16 +0000 (GMT)
+ Authentication-Results: mx.gnu.org; dkim=pass header.i=@gnu.org; spf=pass
+ Message-ID: <abcdef@gnu.org>
+ From: John Doe <jdoe@gnu.org>
+ To: Jane Smith <jsmith@gnu.org>
+
+ # A portable (non-gnu) variation:
+ # sed -e :a -e '$!N;s/\n */ /;ta' -e 'P;D'
+

File: sed.info-t, Node: Centering lines, Next: Increment a number, Prev: Joining lines, Up: Examples
@@ -3415,20 +3818,26 @@ File: sed.info-t, Node: Other Resources, Next: Reporting Bugs, Prev: Limitati
9 Other Resources for Learning About 'sed'
******************************************
-In addition to several books that have been written about 'sed' (either
-specifically or as chapters in books which discuss shell programming),
-one can find out more about 'sed' (including suggestions of a few books)
-from the FAQ for the 'sed-users' mailing list, available from:
- <http://sed.sourceforge.net/sedfaq.html>
+For up to date information about GNU 'sed' please visit
+<https://www.gnu.org/software/sed/>.
+
+ Send general questions and suggestions to <sed-devel@gnu.org>. Visit
+the mailing list archives for past discussions at
+<https://lists.gnu.org/archive/html/sed-devel/>.
+
+ The following resources provide information about 'sed' (both GNU
+'sed' and other variations). Note these not maintained by GNU 'sed'
+developers.
- Also of interest are
-<http://www.student.northpark.edu/pemente/sed/index.htm> and
-<http://sed.sf.net/grabbag>, which include 'sed' tutorials and other
-'sed'-related goodies.
+ * sed '$HOME': <http://sed.sf.net>
- The 'sed-users' mailing list itself maintained by Sven Guckes. To
-subscribe, visit <http://groups.yahoo.com> and search for the
-'sed-users' mailing list.
+ * sed FAQ: <http://sed.sf.net/sedfaq.html>
+
+ * seder's grabbag: <http://sed.sf.net/grabbag>
+
+ * The 'sed-users' mailing list maintained by Sven Guckes:
+ <http://groups.yahoo.com/group/sed-users/> (note this is _not_ the
+ GNU 'sed' mailing list).

File: sed.info-t, Node: Reporting Bugs, Next: GNU Free Documentation License, Prev: Other Resources, Up: Top
@@ -4096,7 +4505,7 @@ exception of the 'sed' commands and command-line options.
* 0 address: Reporting Bugs. (line 114)
* ;, command separator: sed script overview. (line 37)
* a, and semicolons: sed script overview. (line 56)
-* Additional reading about sed: Other Resources. (line 6)
+* Additional reading about sed: Other Resources. (line 13)
* ADDR1,+N: Range Addresses. (line 31)
* ADDR1,~N: Range Addresses. (line 31)
* address range, example: sed script overview. (line 23)
@@ -4118,6 +4527,10 @@ exception of the 'sed' commands and command-line options.
* Append next input line to pattern space: Other Commands. (line 257)
* Append pattern space to hold space: Other Commands. (line 276)
* Appending text after a line: Other Commands. (line 45)
+* b, joining lines with: Branching and flow control.
+ (line 150)
+* b, versus t: Branching and flow control.
+ (line 150)
* back-reference: Back-references and Subexpressions.
(line 6)
* Backreferences, in regular expressions: The "s" Command. (line 18)
@@ -4130,6 +4543,12 @@ exception of the 'sed' commands and command-line options.
(line 22)
* Branch to a label, unconditionally: Programming Commands.
(line 18)
+* branching and n, N: Branching and flow control.
+ (line 105)
+* branching, infinite loop: Branching and flow control.
+ (line 95)
+* branching, joining lines: Branching and flow control.
+ (line 150)
* Buffer spaces, pattern and hold: Execution Cycle. (line 6)
* Bugs, reporting: Reporting Bugs. (line 6)
* c, and semicolons: sed script overview. (line 56)
@@ -4151,6 +4570,8 @@ exception of the 'sed' commands and command-line options.
(line 57)
* Copy hold space into pattern space: Other Commands. (line 280)
* Copy pattern space into hold space: Other Commands. (line 272)
+* cycle, restarting: Branching and flow control.
+ (line 75)
* d, example: sed script overview. (line 23)
* Delete first line from pattern space: Other Commands. (line 251)
* digit characters: Character Classes and Bracket Expressions.
@@ -4272,7 +4693,15 @@ exception of the 'sed' commands and command-line options.
(line 40)
* In-place editing, Perl-style backup file names: Command-Line Options.
(line 51)
+* infinite loop, branching: Branching and flow control.
+ (line 95)
* Inserting text before a line: Other Commands. (line 104)
+* joining lines with branching: Branching and flow control.
+ (line 150)
+* joining quoted-printable lines: Branching and flow control.
+ (line 150)
+* labels: Branching and flow control.
+ (line 75)
* Labels, in scripts: Programming Commands.
(line 14)
* Last line, selecting: Numeric Addresses. (line 13)
@@ -4292,6 +4721,10 @@ exception of the 'sed' commands and command-line options.
(line 80)
* multiple files: Overview. (line 37)
* multiple sed commands: sed script overview. (line 37)
+* n, and branching: Branching and flow control.
+ (line 105)
+* N, and branching: Branching and flow control.
+ (line 105)
* named character classes: Character Classes and Bracket Expressions.
(line 43)
* newline, command separator: sed script overview. (line 37)
@@ -4307,6 +4740,8 @@ exception of the 'sed' commands and command-line options.
* numeric addresses: Addresses overview. (line 6)
* numeric characters: Character Classes and Bracket Expressions.
(line 62)
+* omitting labels: Branching and flow control.
+ (line 75)
* output: Overview. (line 23)
* output, suppressing: Overview. (line 30)
* p, example: Overview. (line 30)
@@ -4338,6 +4773,8 @@ exception of the 'sed' commands and command-line options.
* q, example: sed script overview. (line 28)
* Quitting: Common Commands. (line 28)
* Quitting <1>: Extended Commands. (line 36)
+* quoted-printable lines, joining: Branching and flow control.
+ (line 150)
* range addresses: Addresses overview. (line 24)
* range expression: Character Classes and Bracket Expressions.
(line 18)
@@ -4358,6 +4795,8 @@ exception of the 'sed' commands and command-line options.
(line 78)
* Replacing selected lines with other text: Other Commands. (line 157)
* Requiring GNU sed: Extended Commands. (line 69)
+* restarting a cycle: Branching and flow control.
+ (line 75)
* Sandbox mode: Command-Line Options.
(line 124)
* script parameter: Overview. (line 43)
@@ -4393,6 +4832,10 @@ exception of the 'sed' commands and command-line options.
* suppressing output: Overview. (line 30)
* syntax, addresses: sed script overview. (line 13)
* syntax, sed commands: sed script overview. (line 13)
+* t, joining lines with: Branching and flow control.
+ (line 150)
+* t, versus b: Branching and flow control.
+ (line 150)
* Text, appending: Other Commands. (line 45)
* Text, deleting: Common Commands. (line 44)
* Text, insertion: Other Commands. (line 104)
@@ -4562,69 +5005,70 @@ Ref: Command-Line Options-Footnote-111851
Ref: Command-Line Options-Footnote-212043
Node: Exit status12142
Node: sed scripts13046
-Node: sed script overview13561
-Node: sed commands list16049
-Node: The "s" Command20854
-Ref: The "s" Command-Footnote-126320
-Node: Common Commands26392
-Node: Other Commands29424
-Ref: Other Commands-Footnote-138450
-Node: Programming Commands38522
-Node: Extended Commands39436
-Node: sed addresses43302
-Node: Addresses overview43733
-Node: Numeric Addresses45511
-Node: Regexp Addresses46864
-Ref: Regexp Addresses-Footnote-150251
-Node: Range Addresses50391
-Node: sed regular expressions52873
-Node: Regular Expressions Overview53675
-Node: BRE vs ERE55184
-Node: BRE syntax56778
-Node: ERE syntax63165
-Node: Character Classes and Bracket Expressions64639
-Node: regexp extensions69479
-Node: Back-references and Subexpressions71869
-Node: Escapes74275
-Ref: Escapes-Footnote-176473
-Node: Locale Considerations76664
-Node: advanced sed77935
-Node: Execution Cycle78296
-Ref: Execution Cycle-Footnote-179493
-Node: Hold and Pattern Buffers79794
-Node: Multiline techniques79984
-Node: Branching and flow control83200
-Node: Examples83372
-Node: Joining lines84574
-Node: Centering lines85229
-Node: Increment a number86148
-Ref: Increment a number-Footnote-187627
-Node: Rename files to lower case87747
-Node: Print bash environment90522
-Node: Reverse chars of lines91279
-Ref: Reverse chars of lines-Footnote-192312
-Node: Text search across multiple lines92529
-Node: Line length adjustment95756
-Node: tac98182
-Node: cat -n98951
-Node: cat -b100775
-Node: wc -c101526
-Ref: wc -c-Footnote-1103438
-Node: wc -w103507
-Node: wc -l104973
-Node: head105220
-Node: tail105553
-Node: uniq107236
-Node: uniq -d108025
-Node: uniq -u108738
-Node: cat -s109449
-Node: Limitations111298
-Node: Other Resources112141
-Node: Reporting Bugs112988
-Ref: N_command_last_line114153
-Ref: Reporting Bugs-Footnote-1120298
-Node: GNU Free Documentation License120369
-Node: Concept Index145524
-Node: Command and Option Index170108
+Node: sed script overview13621
+Node: sed commands list16144
+Node: The "s" Command20949
+Ref: The "s" Command-Footnote-126413
+Node: Common Commands26485
+Node: Other Commands29517
+Ref: Other Commands-Footnote-138536
+Node: Programming Commands38608
+Node: Extended Commands39522
+Node: Multiple commands syntax43421
+Node: sed addresses47740
+Node: Addresses overview48171
+Node: Numeric Addresses49949
+Node: Regexp Addresses51302
+Ref: Regexp Addresses-Footnote-154689
+Node: Range Addresses54829
+Node: sed regular expressions57311
+Node: Regular Expressions Overview58113
+Node: BRE vs ERE59622
+Node: BRE syntax61216
+Node: ERE syntax67603
+Node: Character Classes and Bracket Expressions69077
+Node: regexp extensions73917
+Node: Back-references and Subexpressions76307
+Node: Escapes78713
+Ref: Escapes-Footnote-180911
+Node: Locale Considerations81102
+Node: advanced sed82373
+Node: Execution Cycle82734
+Ref: Execution Cycle-Footnote-183931
+Node: Hold and Pattern Buffers84232
+Node: Multiline techniques84422
+Node: Branching and flow control87638
+Node: Examples95689
+Node: Joining lines96891
+Node: Centering lines98680
+Node: Increment a number99599
+Ref: Increment a number-Footnote-1101078
+Node: Rename files to lower case101198
+Node: Print bash environment103973
+Node: Reverse chars of lines104730
+Ref: Reverse chars of lines-Footnote-1105763
+Node: Text search across multiple lines105980
+Node: Line length adjustment109207
+Node: tac111633
+Node: cat -n112402
+Node: cat -b114226
+Node: wc -c114977
+Ref: wc -c-Footnote-1116889
+Node: wc -w116958
+Node: wc -l118424
+Node: head118671
+Node: tail119004
+Node: uniq120687
+Node: uniq -d121476
+Node: uniq -u122189
+Node: cat -s122900
+Node: Limitations124749
+Node: Other Resources125592
+Node: Reporting Bugs126495
+Ref: N_command_last_line127660
+Ref: Reporting Bugs-Footnote-1133805
+Node: GNU Free Documentation License133876
+Node: Concept Index159031
+Node: Command and Option Index186029

End Tag Table
diff --git a/doc/sed.texi b/doc/sed.texi
index 121e405..7cc67d6 100644
--- a/doc/sed.texi
+++ b/doc/sed.texi
@@ -34,7 +34,7 @@
This file documents version @value{VERSION} of
@value{SSED}, a stream editor.
-Copyright @copyright{} 1998-2016 Free Software Foundation, Inc.
+Copyright @copyright{} 1998-2017 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
@@ -484,6 +484,7 @@ $ echo | sed 'Q42' ; echo $?
* Other Commands:: Less frequently used commands
* Programming Commands:: Commands for @command{sed} gurus
* Extended Commands:: Commands specific of @value{SSED}
+* Multiple commands syntax:: Extension for easier scripting
@end menu
@node sed script overview
@@ -586,6 +587,7 @@ thus should be terminated
with newlines or be placed at the end of a @var{script} or @var{script-file}.
Commands can also be preceded with optional non-significant
whitespace characters.
+@xref{Multiple commands syntax}.
@@ -903,12 +905,12 @@ while in general flags for the @code{s} command show their
effect just once. This behavior, although documented, might
change in future versions.
-@item w @var{file-name}
+@item w @var{filename}
@cindex Text, writing to a file after substitution
@cindex @value{SSEDEXT}, @file{/dev/stdout} file
@cindex @value{SSEDEXT}, @file{/dev/stderr} file
If the substitution was made, then write out the result to the named file.
-As a @value{SSED} extension, two special values of @var{file-name} are
+As a @value{SSED} extension, two special values of @var{filename} are
supported: @file{/dev/stderr}, which writes the result to the standard
error, and @file{/dev/stdout}, which writes to the standard
output.@footnote{This is equivalent to @code{p} unless the @option{-i}
@@ -1149,7 +1151,7 @@ hello
@codequoteundirected off
@codequotebacktick off
-Leading whitespaces after the @code{a} command are ignored.
+Leading whitespace after the @code{a} command is ignored.
The text to add is read until the end of the line.
@@ -1238,7 +1240,7 @@ hello
@codequoteundirected off
@codequotebacktick off
-Leading whitespaces after the @code{i} command are ignored.
+Leading whitespace after the @code{i} command is ignored.
The text to add is read until the end of the line.
@item i\
@@ -1319,7 +1321,7 @@ hello
@codequoteundirected off
@codequotebacktick off
-Leading whitespaces after the @code{c} command are ignored.
+Leading whitespace after the @code{c} command is ignored.
The text to add is read until the end of the line.
@item c\
@@ -1464,7 +1466,7 @@ file will then be reread and inserted on each of the addressed lines.
@cindex @value{SSEDEXT}, @file{/dev/stdout} file
@cindex @value{SSEDEXT}, @file{/dev/stderr} file
Write the pattern space to @var{filename}.
-As a @value{SSED} extension, two special values of @var{file-name} are
+As a @value{SSED} extension, two special values of @var{filename} are
supported: @file{/dev/stderr}, which writes the result to the standard
error, and @file{/dev/stdout}, which writes to the standard
output.@footnote{This is equivalent to @code{p} unless the @option{-i}
@@ -1706,7 +1708,283 @@ script in most multibyte locales (including UTF-8 locales).
@end table
+@node Multiple commands syntax
+@section Multiple commands syntax
+
+@c POSIX says:
+@c Editing commands other than {...}, a, b, c, i, r, t, w, :, and #
+@c can be followed by a <semicolon>, optional <blank> characters, and
+@c another editing command. However, when an s editing command is used
+@c with the w flag, following it with another command in this manner
+@c produces undefined results.
+
+There are several methods to specify multiple commands in a @command{sed}
+program.
+
+Using newlines is most natural when running a sed script from a file
+(using the @option{-f} option).
+
+On the command line, all @command{sed} commands may be separated by newlines.
+Alternatively, you may specify each command as an argument to an @option{-e}
+option:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 6 | sed '1d
+3d
+5d'
+2
+4
+6
+
+$ seq 6 | sed -e 1d -e 3d -e 5d
+2
+4
+6
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+A semicolon (@samp{;}) may be used to separate most simple commands:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 6 | sed '1d;3d;5d'
+2
+4
+6
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+The @code{@{},@code{@}},@code{b},@code{t},@code{T},@code{:} commands can
+be separated with a semicolon (this is a non-portable @value{SSED} extension).
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 4 | sed '@{1d;3d@}'
+2
+4
+
+$ seq 6 | sed '@{1d;3d@};5d'
+2
+4
+6
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+Labels used in @code{b},@code{t},@code{T},@code{:} commands are read
+until a semicolon. Leading and trailing whitespace is ignored. In
+the examples below the label is @samp{x}. The first example works
+with @value{SSED}. The second is a portable equivalent. For more
+information about branching and labels @pxref{Branching and flow
+control}.
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 3 | sed '/1/b x ; s/^/=/ ; :x ; 3d'
+1
+=2
+
+$ seq 3 | sed -e '/1/bx' -e 's/^/=/' -e ':x' -e '3d'
+1
+=2
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+
+
+@subsection Commands Requiring a newline
+
+The following commands cannot be separated by a semicolon and
+require a newline:
+
+@table @asis
+
+@item @code{a},@code{c},@code{i} (append/change/insert)
+
+All characters following @code{a},@code{c},@code{i} commands are taken
+as the text to append/change/insert. Using a semicolon leads to
+undesirable results:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 2 | sed '1aHello ; 2d'
+1
+Hello ; 2d
+2
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+Separate the commands using @option{-e} or a newline:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 2 | sed -e 1aHello -e 2d
+1
+Hello
+
+$ seq 2 | sed '1aHello
+2d'
+1
+Hello
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+Note that specifying the text to add (@samp{Hello}) immediately
+after @code{a},@code{c},@code{i} is itself a @value{SSED} extension.
+A portable, POSIX-compliant alternative is:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 2 | sed '1a\
+Hello
+2d'
+1
+Hello
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+@item @code{#} (comment)
+
+All characters following @samp{#} until the next newline are ignored.
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 3 | sed '# this is a comment ; 2d'
+1
+2
+3
+
+
+$ seq 3 | sed '# this is a comment
+2d'
+1
+3
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+@item @code{r},@code{R},@code{w},@code{W} (reading and writing files)
+
+The @code{r},@code{R},@code{w},@code{W} commands parse the filename
+until end of the line. If whitespace, comments or semicolons are found,
+they will be included in the filename, leading to unexpected results:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 2 | sed '1w hello.txt ; 2d'
+1
+2
+
+$ ls -log
+total 4
+-rw-rw-r-- 1 2 Jan 23 23:03 hello.txt ; 2d
+
+$ cat 'hello.txt ; 2d'
+1
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+Note that @command{sed} silently ignores read/write errors in
+@code{r},@code{R},@code{w},@code{W} commands (such as missing files).
+In the following example, @command{sed} tries to read a file named
+@samp{@file{hello.txt ; N}}. The file is missing, and the error is silently
+ignored:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ echo x | sed '1rhello.txt ; N'
+x
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+@item @code{e} (command execution)
+
+Any characters following the @code{e} command until the end of the line
+will be sent to the shell. If whitespace, comments or semicolons are found,
+they will be included in the shell command, leading to unexpected results:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ echo a | sed '1e touch foo#bar'
+a
+
+$ ls -1
+foo#bar
+
+$ echo a | sed '1e touch foo ; s/a/b/'
+sh: 1: s/a/b/: not found
+a
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+
+@item @code{s///[we]} (substitute with @code{e} or @code{w} flags)
+
+In a substitution command, the @code{w} flag writes the substitution
+result to a file, and the @code{e} flag executes the subsitution result
+as a shell command. As with the @code{r/R/w/W/e} commands, these
+must be terminated with a newline. If whitespace, comments or semicolons
+are found, they will be included in the shell command or filename, leading to
+unexpected results:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ echo a | sed 's/a/b/w1.txt#foo'
+b
+
+$ ls -1
+1.txt#foo
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+@end table
@node sed addresses
@@ -3085,7 +3363,7 @@ command appends a newline and the next line to the pattern space
(i.e. @samp{1}, @samp{\n}, @samp{2} in the first cycle).
@item
The @code{l} command prints the content of the pattern space
-unambigiously.
+unambiguously.
@item
The @code{D} command then removes the content of pattern
space up to the first newline (leaving @samp{2} at the end of
@@ -3173,7 +3451,303 @@ and @ref{Line length adjustment}.
@node Branching and flow control
@section Branching and Flow Control
-TODO
+The branching commands @code{b}, @code{t}, and @code{T} enable
+changing the flow of @command{sed} programs.
+
+By default, @command{sed} reads an input line into the pattern buffer,
+then continues to processes all commands in order.
+Commands without addresses affect all lines.
+Commands with addresses affect only matching lines.
+@xref{Execution Cycle} and @ref{Addresses overview}.
+
+@command{sed} does not support a typical @code{if/then} construct.
+Instead, some commands can be used as conditionals or to change the
+default flow control:
+
+@table @code
+
+@item d
+delete (clears) the current pattern space,
+and restart the program cycle without processing the rest of the commands
+and without printing the pattern space.
+
+@item D
+delete the contents of the pattern space @emph{up to the first newline},
+and restart the program cycle without processing the rest of
+the commands and without printing the pattern space.
+
+@item [addr]X
+@itemx [addr]@{ X ; X ; X @}
+@item /regexp/X
+@item /regexp/@{ X ; X ; X @}
+Addresses and regular expressions can be used as an @code{if/then}
+conditional: If @var{[addr]} matches the current pattern space,
+execute the command(s).
+For example: The command @code{/^#/d} means:
+@emph{if} the current pattern matches the regular expression @code{^#} (a line
+starting with a hash), @emph{then} execute the @code{d} command:
+delete the line without printing it, and restart the program cycle
+immediately.
+
+@item b
+branch unconditionally (that is: always jump to a label, skipping
+or repeating other commands, without restarting a new cycle). Combined
+with an address, the branch can be conditionally executed on matched
+lines.
+
+@item t
+branch conditionally (that is: jump to a label) @emph{only if} a
+@code{s///} command has succeeded since the last input line was read
+or another conditional branch was taken.
+
+@item T
+similar but opposite to the @code{t} command: branch only if
+there has been @emph{no} successful substitutions since the last
+input line was read.
+@end table
+
+
+The following two @command{sed} programs are equivalent. The first
+(contrived) example uses the @code{b} command to skip the @code{s///}
+command on lines containing @samp{1}. The second example uses an
+address with negation (@samp{!}) to perform substitution only on
+desired lines. The @code{y///} command is still executed on all
+lines:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ printf '%s\n' a1 a2 a3 | sed -E '/1/bx ; s/a/z/ ; :x ; y/123/456/'
+a4
+z5
+z6
+
+$ printf '%s\n' a1 a2 a3 | sed -E '/1/!s/a/z/ ; y/123/456/'
+a4
+z5
+z6
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+
+
+@subsection Branching and Cycles
+@cindex labels
+@cindex omitting labels
+@cindex cycle, restarting
+@cindex restarting a cycle
+The @code{b},@code{t} and @code{T} commands can be followed by a label
+(typically a single letter). Labels are defined with a colon followed by
+one or more letters (e.g. @samp{:x}). If the label is omitted the
+branch commands restart the cycle. Note the difference between
+branching to a label and restarting the cycle: when a cycle is
+restarted, @command{sed} first prints the current content of the
+pattern space, then reads the next input line into the pattern space;
+Jumping to a label (even if it is at the beginning of the program)
+does not print the pattern space and does not read the next input line.
+
+The following program is a no-op. The @code{b} command (the only command
+in the program) does not have a label, and thus simply restarts the cycle.
+On each cycle, the pattern space is printed and the next input line is read:
+
+@example
+@group
+$ seq 3 | sed b
+1
+2
+3
+@end group
+@end example
+
+@cindex infinite loop, branching
+@cindex branching, infinite loop
+The following example is an infinite-loop - it doesn't terminate and
+doesn't print anything. The @code{b} command jumps to the @samp{x}
+label, and a new cycle is never started:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 3 | sed ':x ; bx'
+
+# The above command requires gnu sed (which supports additional
+# commands following a label, without a newline). A portable equivalent:
+# sed -e ':x' -e bx
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+@cindex branching and n, N
+@cindex n, and branching
+@cindex N, and branching
+Branching is often complemented with the @code{n} or @code{N} commands:
+both commands read the next input line into the pattern space without waiting
+for the cycle to restart. Before reading the next input line, @code{n}
+prints the current pattern space then empties it, while @code{N}
+appends a newline and the next input line to the pattern space.
+
+Consider the following two examples:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ seq 3 | sed ':x ; n ; bx'
+1
+2
+3
+
+$ seq 3 | sed ':x ; N ; bx'
+1
+2
+3
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+@itemize
+@item
+Both examples do not inf-loop, despite never starting a new cycle.
+
+@item
+In the first example, the @code{n} commands first prints the content
+of the pattern space, empties the pattern space then reads the next
+input line.
+
+@item
+In the second example, the @code{N} commands appends the next input
+line to the pattern space (with a newline). Lines are accumulated in
+the pattern space until there are no more input lines to read, then
+the @code{N} command terminates the @command{sed} program. When the
+program terminates, the end-of-cycle actions are performed, and the
+entire pattern space is printed.
+
+@item
+The second example requires @value{SSED},
+because it uses the non-POSIX-standard behavior of @code{N}.
+See the ``@code{N} command on the last line'' paragraph
+in @ref{Reporting Bugs}.
+
+@item
+To further examine the difference between the two examples,
+try the following commands:
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+printf '%s\n' aa bb cc dd | sed ':x ; n ; = ; bx'
+printf '%s\n' aa bb cc dd | sed ':x ; N ; = ; bx'
+printf '%s\n' aa bb cc dd | sed ':x ; n ; s/\n/***/ ; bx'
+printf '%s\n' aa bb cc dd | sed ':x ; N ; s/\n/***/ ; bx'
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+@end itemize
+
+
+
+@subsection Branching example: joining lines
+
+@cindex joining lines with branching
+@cindex branching, joining lines
+@cindex quoted-printable lines, joining
+@cindex joining quoted-printable lines
+@cindex t, joining lines with
+@cindex b, joining lines with
+@cindex b, versus t
+@cindex t, versus b
+As a real-world example of using branching, consider the case of
+@uref{https://en.wikipedia.org/wiki/Quoted-printable,quoted-printable} files,
+typically used to encode email messages.
+In these files long lines are split and marked with a @dfn{soft line break}
+consisting of a single @samp{=} character at the end of the line:
+
+@example
+@group
+$ cat jaques.txt
+All the wor=
+ld's a stag=
+e,
+And all the=
+ men and wo=
+men merely =
+players:
+They have t=
+heir exits =
+and their e=
+ntrances;
+And one man=
+ in his tim=
+e plays man=
+y parts.
+@end group
+@end example
+
+
+The following program uses an address match @samp{/=$/} as a
+conditional: If the current pattern space ends with a @samp{=}, it
+reads the next input line using @code{N}, replaces all @samp{=}
+characters which are followed by a newline, and unconditionally
+branches (@code{b}) to the beginning of the program without restarting
+a new cycle. If the pattern space does not ends with @samp{=}, the
+default action is performed: the pattern space is printed and a new
+cycle is started:
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ sed ':x ; /=$/ @{ N ; s/=\n//g ; bx @}' jaques.txt
+All the world's a stage,
+And all the men and women merely players:
+They have their exits and their entrances;
+And one man in his time plays many parts.
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+Here's an alternative program with a slightly different approach: On
+all lines except the last, @code{N} appends the line to the pattern
+space. A substitution command then removes soft line breaks
+(@samp{=} at the end of a line, i.e. followed by a newline) by replacing
+them with an empty string.
+@emph{if} the substitution was successful (meaning the pattern space contained
+a line which should be joined), The conditional branch command @code{t} jumps
+to the beginning of the program without completing or restarting the cycle.
+If the substitution failed (meaning there were no soft line breaks),
+The @code{t} command will @emph{not} branch. Then, @code{P} will
+print the pattern space content until the first newline, and @code{D}
+will delete the pattern space content until the first new line.
+(To learn more about @code{N}, @code{P} and @code{D} commands
+@pxref{Multiline techniques}).
+
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ sed ':x ; $!N ; s/=\n// ; tx ; P ; D' jaques.txt
+All the world's a stage,
+And all the men and women merely players:
+They have their exits and their entrances;
+And one man in his time plays many parts.
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+
+For more line-joining examples @pxref{Joining lines}.
+
@node Examples
@chapter Some Sample Scripts
@@ -3213,6 +3787,10 @@ Emulating standard utilities:
@node Joining lines
@section Joining lines
+This section uses @code{N}, @code{D} and @code{P} commands to process
+multiple lines, and the @code{b} and @code{t} commands for branching.
+@xref{Multiline techniques} and @ref{Branching and flow control}.
+
Join specific lines (e.g. if lines 2 and 3 need to be joined):
@codequoteundirected on
@@ -3232,7 +3810,7 @@ hello
@codequoteundirected off
@codequotebacktick off
-Join lines ending with backslashes:
+Join backslash-continued lines:
@codequoteundirected on
@codequotebacktick on
@@ -3257,6 +3835,42 @@ and another line
@codequoteundirected off
@codequotebacktick off
+Join lines that start with whitespace (e.g SMTP headers):
+
+@codequoteundirected on
+@codequotebacktick on
+@example
+@group
+$ cat 2.txt
+Subject: Hello
+ World
+Content-Type: multipart/alternative;
+ boundary=94eb2c190cc6370f06054535da6a
+Date: Tue, 3 Jan 2017 19:41:16 +0000 (GMT)
+Authentication-Results: mx.gnu.org;
+ dkim=pass header.i=@@gnu.org;
+ spf=pass
+Message-ID: <abcdef@@gnu.org>
+From: John Doe <jdoe@@gnu.org>
+To: Jane Smith <jsmith@@gnu.org>
+
+$ sed -E ':a ; $!N ; s/\n\s+/ / ; ta ; P ; D' 2.txt
+Subject: Hello World
+Content-Type: multipart/alternative; boundary=94eb2c190cc6370f06054535da6a
+Date: Tue, 3 Jan 2017 19:41:16 +0000 (GMT)
+Authentication-Results: mx.gnu.org; dkim=pass header.i=@@gnu.org; spf=pass
+Message-ID: <abcdef@@gnu.org>
+From: John Doe <jdoe@@gnu.org>
+To: Jane Smith <jsmith@@gnu.org>
+
+# A portable (non-gnu) variation:
+# sed -e :a -e '$!N;s/\n */ /;ta' -e 'P;D'
+@end group
+@end example
+@codequoteundirected off
+@codequotebacktick off
+
+
@node Centering lines
@section Centering Lines
@@ -4505,24 +5119,35 @@ the size of the buffer that can be processed by certain patterns.
@node Other Resources
@chapter Other Resources for Learning About @command{sed}
+For up to date information about @value{SSED} please
+visit @uref{https://www.gnu.org/software/sed/}.
+
+Send general questions and suggestions to @email{sed-devel@@gnu.org}.
+Visit the mailing list archives for past discussions at
+@uref{https://lists.gnu.org/archive/html/sed-devel/}.
+
@cindex Additional reading about @command{sed}
-In addition to several books that have been written about @command{sed}
-(either specifically or as chapters in books which discuss
-shell programming), one can find out more about @command{sed}
-(including suggestions of a few books) from the FAQ
-for the @code{sed-users} mailing list, available from:
-@display
-@uref{http://sed.sourceforge.net/sedfaq.html}
-@end display
-
-Also of interest are
-@uref{http://www.student.northpark.edu/pemente/sed/index.htm}
-and @uref{http://sed.sf.net/grabbag},
-which include @command{sed} tutorials and other @command{sed}-related goodies.
-
-The @code{sed-users} mailing list itself maintained by Sven Guckes.
-To subscribe, visit @uref{http://groups.yahoo.com} and search
-for the @code{sed-users} mailing list.
+The following resources provide information about @command{sed}
+(both @value{SSED} and other variations). Note these not maintained by
+@value{SSED} developers.
+
+@itemize @bullet
+
+@item
+sed @code{$HOME}: @uref{http://sed.sf.net}
+
+@item
+sed FAQ: @uref{http://sed.sf.net/sedfaq.html}
+
+@item
+seder's grabbag: @uref{http://sed.sf.net/grabbag}
+
+@item
+The @code{sed-users} mailing list maintained by Sven Guckes:
+@uref{http://groups.yahoo.com/group/sed-users/}
+(note this is @emph{not} the @value{SSED} mailing list).
+
+@end itemize
@node Reporting Bugs
@chapter Reporting Bugs
diff --git a/doc/stamp-vti b/doc/stamp-vti
index cc4d7e0..803c837 100644
--- a/doc/stamp-vti
+++ b/doc/stamp-vti
@@ -1,4 +1,4 @@
-@set UPDATED 30 December 2016
-@set UPDATED-MONTH December 2016
-@set EDITION 4.3
-@set VERSION 4.3
+@set UPDATED 3 February 2017
+@set UPDATED-MONTH February 2017
+@set EDITION 4.4
+@set VERSION 4.4
diff --git a/doc/version.texi b/doc/version.texi
index cc4d7e0..803c837 100644
--- a/doc/version.texi
+++ b/doc/version.texi
@@ -1,4 +1,4 @@
-@set UPDATED 30 December 2016
-@set UPDATED-MONTH December 2016
-@set EDITION 4.3
-@set VERSION 4.3
+@set UPDATED 3 February 2017
+@set UPDATED-MONTH February 2017
+@set EDITION 4.4
+@set VERSION 4.4