Hi!

Line numbers from Issue 8 (C243).

116577  DESCRIPTION
116578    The tail utility shall copy its input file to the standard output 
beginning at a designated place.

116579    Copying shall begin at the point in the file indicated by the −c 
number or −n number options. The
116580    option-argument number shall be counted in units of lines or bytes, 
according to the options −n
116581    and −c. Both line and byte counts start from 1.

(So tail is defined in terms of "seek to start of data, dump to end".)


116584  OPTIONS
116588  −c number  The application shall ensure that the number option-argument 
is a decimal integer,
116589             optionally including a sign. The sign shall affect the 
location in the file, measured
116590             in bytes, to begin the copying:

116591               Sign  Copying Starts
116592               +     Relative to the beginning of the file.
116593               −     Relative to the end of the file.
116594               none  Relative to the end of the file.

116595             The application shall ensure that if the sign of the number 
option-argument is '+',
116596             the number option-argument is a non-zero decimal integer.

116597             The origin for counting shall be 1; that is, −c +1 
represents the first byte of the file,
116598             −c −1 the last.

116605  −n number  If −r is not specified, this option shall be equivalent to 
−c number, except the
116606             starting location in the file shall be measured in lines 
instead of bytes. The origin
116607             for counting shall be 1; that is, −n +1 represents the first 
line of the file, −n −1 the
116608             last.

(So -n 2 and -n -2 mean "start of data is start of line before the last".)


Thus (and knowing that a line is 
  1800  A sequence of zero or more non-<newline> characters plus a terminating 
<newline> character.
), given
  $ printf 'abc\ndef\nghi\njkl' > l

We can thus analyse it into lines:
  1. abc\n
  2. def\n
  3. ghi\n
(also some garbage)

Thus the following must hold:
  $ tail -n 2 l; echo
  def
  ghi
  jkl
since tail sought to start of the line before the last (2) and dumped 'til end.

But this is both obviously wrong and also not how any implementation
behaves. GNU coreutils and FreeBSD and NetBSD and the illumos gate
all do the expected thing of
  $ tail -n 2 l; echo
  ghi
  jkl

Maybe add something to the effect of ", except the starting location
in the file shall be measured in lines or partial lines instead of bytes."?

Best,
наб

Attachment: signature.asc
Description: PGP signature

Reply via email to