Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Weirdness in comm(1)



On Sun, 6 Dec 2009 21:09:40 +0100
Rhialto <rhialto%falu.nl@localhost> wrote:
> On Sat 28 Nov 2009 at 20:29:23 -0500, Greg A. Woods wrote:
> > I think it may be easier and safer all around to always think of
> > newlines as separators rather than as _necessary_ terminators in unix
> > text files.
> 
> No. Newlines are required at the end of each line.

Somewhat semantical but let's explore this.  What if I create a file
like this:

#include "stdio.h"
int
main(void)
{
   FILE *fp;
   fp = fopen("MyFile.txt", "w");
   fprintf(fp, "abc\ndef\nghi");
   fclose(fp);
   return 0;
}

How many lines does that file have?  Common sense would suggest three
but if we take your statement as gospel truth then it only has two.  At
least sort(1) and cat(1) get this wrong according to you.

> Quote from K&R, 2nd edition, page 151, par 7.1, "Standard Input and
> Output":
>
>    A text stream consists of a sequence of lines; each line ends with a
>    newline character.

I think that this statement needs to be amended at this point rather
than changing just about every Unix program that operates on text files.

Greg's methodology above may not match the letter of the law but your
programs will be less surprising to your clients if you follow it.

-- 
D'Arcy J.M. Cain <darcy%NetBSD.org@localhost>
http://www.NetBSD.org/


Home | Main Index | Thread Index | Old Index