Problem using multiple 'head' commands in shell script
Gary Bartlett
garyb at abekrd.UUCP
Wed Jan 30 04:47:25 AEST 1991
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 at 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
More information about the Comp.unix.shell
mailing list