Bug 160745

Summary: sed(1) appends '\n' at the end of binary data (unlike gsed(1))
Product: Base System Reporter: Wojciech A. Koszek <wkoszek>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: dumbbell
Priority: Normal    
Version: 8.2-STABLE   
Hardware: Any   
OS: Any   

Description Wojciech A. Koszek freebsd_committer freebsd_triage 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.

Run:
http://freebsd.czest.pl/~wkoszek/stuff/freebsd/sed_problem.sh

Script below.

#!/bin/sh

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 freebsd_triage 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

Log:
  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

Changes:
  head/usr.bin/sed/defs.h
  head/usr.bin/sed/main.c
  head/usr.bin/sed/process.c
  head/usr.bin/sed/tests/regress.y.out
Comment 2 Jean-Sébastien Pédron freebsd_committer freebsd_triage 2014-08-08 17:32:03 UTC
Committed in 11-CURRENT.