[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ed: please give me a little control over appending final newlines
From: |
Andrew L. Moore |
Subject: |
Re: ed: please give me a little control over appending final newlines |
Date: |
28 Feb 2002 23:24:53 -0800 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Cuyahoga Valley) |
In message <address@hidden>, Dan Jacobson writes:
>The ed manual says:
> If a text (non-binary) file is not terminated by a newline
> character, then ed appends one on reading/writing it. In
> the case of a binary file, ed does not append a newline on
> reading/writing.
>
The manual is ambiguous. The source file `POSIX' explains more clearly:
To assist in binary editing, when a file containing at least one ASCII
NUL character is written, a newline is not appended if it did not
already contain one upon reading.
>OK, please give me final control of this action thru a command line
>switch to override ed's choice if I need to.
A command-line switch is unnecessary. Appending blank lines always
appends newlines. Suppressing the trailing newline can be done with
a command sequence such as:
$ ed -s file <<EOF
? r !dd if=/dev/zero bs=1 count=1 2>/dev/null
? d
? wq
? EOF
$
I.e., append a "binary" file with no trailing newline - the output of
the dd command. Subsequently deleting the appended file does not change
the "binary with no trailing newline" status.
>Don't just keep the decision behind my back with not even a definition
>of just exactly what ed believes are "text (non-binary) files".
ed never _removes_ characters from a file - even behind your back, and
when it inserts one during an interactive session, a diagnostic explicitly
states this.
>And, if it is so smart, why doesn't it know about what happens if you
>just add a NL to a CR-LF file? I wouldn't complain if I had a way to
>control ed.
Format conversion is better handled separately:
#!/bin/sh -
#
# @(#)jed
#
# This script is an ed(1) front-end for handling arbitrary file formats.
#
umask 077
PATH=/bin:/usr/bin:/usr/local/bin
TMP="unix-format.$$"
argv=""
while [ $# -ne 1 ]; do argv="$argv \"$1\""; shift; done
pathname="$1"
eval set -- "$argv"
case $(file "$pathname") in
*'CRLF line terminators'*)
trap 'rm -f "$TMP"; exit' 0 1 2 15
msdos2unix <"$pathname" >"$TMP"
if [ ."$@" = . ]; then ed "$TMP"; else ed "$@" "$TMP"; fi
unix2msdos <"$TMP" >"$pathname"
;;
*)
if [ ."$@" = . ]; then ed "$pathname"; else ed "$@" "$pathname"; fi
;;
esac
# EOF
-AM
- Re: ed: please give me a little control over appending final newlines,
Andrew L. Moore <=