sort + head = weirdness?

From: Mark (unixadmin_at_livebridge.com)
Date: 10/02/03


Date: Wed, 01 Oct 2003 15:29:17 -0700

This is really weird. I'm catting a text file, piping it through
'sort'and then through 'head' and I'm getting really strange results.

This only affects files > 4096 bytes.
It's only a problem when piping through 'head'; 'tail' works fine.
It's only a problem when piping through a file containing 'sort'; it
works fine with 'sort' itself.

(The test file is just a text file containing the numbers 1-9 repeated.)
('format' is a file containing the single word 'sort'. Eventually this
will contain other formatting commands.)

So, here's what happens:

With a file 4096 bytes or less it works fine.
# ls -al testfile -rw-rw-r--
   1 root root 4096 Oct 1 14:46 testfile

# cat testfile | format | head -1
12345

If I add one more character to the file, it fails.
# ls -al testfile
-rw-rw-r-- 1 root root 4097 Oct 1 14:38 testfile

# cat testfile | format | head -1
123456
/usr/local/bin/drs/format: line 1: 8688 Broken pipe sort

If, with the same 4097 byte file I replace 'head' with 'tail', it works
fine.
# cat testfile | format | tail -1
123456789

If I replace 'format' with 'sort' it works fine.
# cat testfile | sort |head -1
123456

Any idea what's going on here? Is there some buffer somewhere that can
only take 4k of data?

Mark



Relevant Pages

  • Re: Change field format programmatically
    ... Good generalization. ... and use its GotFocus event to immediately set the focus ... item type piping itme number ver-4567890 a dd ... Is ther a way I can alter the format so that when the record is dispayed it ...
    (microsoft.public.access.modulesdaovba)
  • Re: Tailpipe options for 90 GT
    ... talking some sort of GT exhaust system? ... piping is WAY too big for the average street 5-liter car. ...
    (rec.autos.makers.ford.mustang)
  • Re: Change field format programmatically
    ... Private Function MyFormat(num, typ) As Variant ... item type piping itme number ver-4567890 a dd ... Is ther a way I can alter the format so that when the record is dispayed it ...
    (microsoft.public.access.modulesdaovba)
  • Re: Change field format programmatically
    ... Create an text box to display the formatted value. ... and use its GotFocus event to immediately set the focus ... item type piping itme number ver-4567890 a dd ... Is ther a way I can alter the format so that when the record is dispayed it ...
    (microsoft.public.access.modulesdaovba)
  • Re: Preferred Backup Method?
    ... piping through SSH before, so any sort of help would be appreciated. ... SSH will go into command mode if your tar output happens to contain a line ... If programmers deserve to be rewarded for creating innovative ...
    (Debian-User)