Bug 160745 - sed(1) appends '\n' at the end of binary data (unlike gsed(1))
Summary: sed(1) appends '\n' at the end of binary data (unlike gsed(1))
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 8.2-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2011-09-15 02:50 UTC by Wojciech A. Koszek
Modified: 2014-08-08 17:32 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Wojciech A. Koszek freebsd_committer 2011-09-15 02:50:05 UTC
File has ASCII data followed by binary data.

ASCII data contains lines. Binary data contains 0's and follows.

I use sed(1) to delete lines and present me the rest of the content in
untouched form. In other words: I want to get binary data streamed
throught sed(1) without modification.

Currently sed(1) appends '\n' at the end of such data.

gsed(1) works as expected.

While gsed(1) just pipes binary data without a problem, we
pipe data, but append '\n' at the end.

How-To-Repeat: Install ports/textproc/gsed for comparison.


Script below.


echo 1 > data
echo 2 >> data
echo 3 >> data
dd if=/dev/zero bs=1m count=1 >> data
echo "========== WE ========="
cat data | sed '1,3 d' | hexdump -c | tail -5
echo "========== GNU ========"
cat data | gsed '1,3 d' | hexdump -c | tail -5
Comment 1 commit-hook freebsd_committer 2014-08-08 17:29:54 UTC
A commit references this bug:

Author: dumbbell
Date: Fri Aug  8 17:29:02 UTC 2014
New revision: 269729
URL: http://svnweb.freebsd.org/changeset/base/269729

  sed(1): Don't force a newline on last line, if input stream doesn't have one

  While here, change how we check if the current line is the last one.
  Before, we just checked if there were more files after the current one.
  Now, we check the actual content of those files: they files may not have
  a line at all. This matches the definition of the "last line" by the
  Open Group.

  The new behavior is closer to GNU sed.

  PR:		160745
  Phabric:	https://phabric.freebsd.org/D431
  Reviewed by:	jilles
  Approved by:	jilles
  Exp-run by:	antoine

Comment 2 Jean-Sébastien Pédron freebsd_committer 2014-08-08 17:32:03 UTC
Committed in 11-CURRENT.