Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!pyrltd!abekrd!garyb From: garyb@abekrd.UUCP (Gary Bartlett) Newsgroups: comp.unix.shell Subject: Problem using multiple 'head' commands in shell script Keywords: head shell buffering Message-ID: <1671@abekrd.UUCP> Date: 29 Jan 91 17:47:25 GMT Organization: Abekas Video Systems Ltd, Reading, England Lines: 36 Can someone explain to me what is happening with the following Bourne shell script and more importantly how I can get around it: #!/bin/sh cat file | ( head -200 echo "Line 201 follows" head -200 echo "Line 401 follows" cat ) I am trying to use 'head' as a quick way to split up an input stream. I originally used 'read' and an 'expr' counter but this was too slow. This script loses lines after each 'head'. eg if file contained a stream of numbers, the output would be missing lots of numbers! It looks like 'head' initially reads in a whole buffer of data from file (stdin), prints out the requisite number of lines and then dumps the rest of the buffer. The next 'head' then reads the NEXT buffer. Is this right/normal? How can I get around this (preferably whilst still using 'head'). Is it possible to change the buffering within this script? Pointers, anyone? Thanks, Gary -- --------------------------------------------------------------------------- Gary C. Bartlett NET: garyb@abekrd.co.uk Abekas Video Systems Ltd. UUCP: ...!uunet!mcsun!ukc!pyrltd!abekrd!garyb 12 Portman Rd, Reading, PHONE: +44 734 585421 Berkshire. RG3 1EA. FAX: +44 734 567904 United Kingdom. TELEX: 847579