[Bug 260450] Documentation for 'sed' is misleading w.r.t. files that do not end in newlines
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 15 Dec 2021 20:46:35 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260450
Bug ID: 260450
Summary: Documentation for 'sed' is misleading w.r.t. files
that do not end in newlines
Product: Base System
Version: Unspecified
Hardware: Any
OS: Any
Status: New
Severity: Affects Many People
Priority: ---
Component: bin
Assignee: bugs@FreeBSD.org
Reporter: jwdevel@gmail.com
When a text file does not have a terminating newline, sed seems to behave
contrary to its documentation.
Example:
$ echo -n asdf > file.txt
$ wc -c file.txt
4 file.txt
$ sed -n p foo.txt | wc -c
4
In other words, sed does *not* add a newline for the last line in this file.
However, the sed(1) manpage says:
Normally, sed cyclically copies a line of input, not including its
terminating newline character, into a pattern space, (unless there is
something left after a āDā function), applies all of the commands with
addresses that select that pattern space, copies the pattern space to the
standard output, appending a newline, and deletes the pattern space.
In my reading of this, sed should _always_ output a newline, even if its input
did not have one. But that does not seem to be the case.
A little further info:
$ sed -n l foo.txt
asdf$
The 'l' command outputs the pattern space. In fact, this pattern space
("asdf$") is the same regardless of whether the input file has the terminating
newline or not.
Therefore, when the docs say "... copies the pattern space to the standard
output, appending a newline," this seems clearly incorrect.
--
You are receiving this mail because:
You are the assignee for the bug.