On Tue, 23 Sep 2014 16:27:06 -0500, Bill Godfrey wrote:
>
>>o Is there a utility that will append "\n" only if the file doesn't already
>>contain one?
>
>#!/bin/sh
>if [ $# -gt 0 ] ; then
> endbyte=`tail -c1 $1 | od -tc -An | awk '{ print $1 }'`
> if [ "${endbyte}" != '\n' ] ; then
> echo >> $1
> fi
>fi
>
Ah! I failed to think of the "tail -c1". I see you've struggled with
this and won.
o It modifies its input file. But that's what I asked for.
o It converts an empty file to a file of one empty line. That's
literally what I asked for; I should have said, "... append "\n"
only if the file has an incomplete last line."
A simplification, fixing my unintended second requirement:
#!/bin/sh
if [ $# -gt 0 ] ; then
case "$(tail -c1 "$1")" in
'' | '
' );;
*) echo >>"$1";; esac
fi
Thanks. Now IBM-MAIN can return to its proper function of discussing
what's the fastest way to clear a register.
Thanks again,
gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN