On 12/01/2014 02:06 PM, Pádraig Brady wrote:
If we were just implementing now, I'd not output the extra '\n',
I have just the opposite kneejerk reaction; typically text-based apps are simpler and easier to document and use when they silently pretend that the input had a trailing newline. That's what 'awk' and 'grep' do, for example, and they works fine. There are some solid counterexamples (e.g., Emacs, diff) but they have good reasons to be counterexamples.
a newline should only be added where needed, especially with a low level tool like sed.
I'm afraid 'sed' is not that low-level, and GNU sed's current behavior is inconsistent. Sometimes it silently appends a trailing newline to the input before processing it, and sometimes it doesn't:
$ printf x | sed '$a\ > y' x y $ printf x | sed 's/$/y/' xy$
changing at this stage needs to be carefully considered
Yes, the use cases are key here.