Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!ichthous.Eng.Sun.COM!mcgrew From: mcgrew@ichthous.Eng.Sun.COM (Darin McGrew) Newsgroups: comp.unix.shell Subject: Re: Problem using multiple 'head' commands in shell script Keywords: head shell buffering Message-ID: <6925@exodus.Eng.Sun.COM> Date: 30 Jan 91 01:52:08 GMT References: <1671@abekrd.UUCP> Sender: news@exodus.Eng.Sun.COM Organization: Sun Microsystems, Mt. View, Ca. Lines: 34 In article <1671@abekrd.UUCP> garyb@abekrd.UUCP (Gary Bartlett) writes: ->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 -> ) -> ->... ->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.... Yes, head reads a bufferful at a time. I'd use awk: awk ' NR==201 {print "Line 201 follows"} NR==401 {print "Line 401 follows"} {print}' < file ->Thanks, ->Gary You're welcome. Darin McGrew "The Beginning will make all things new, mcgrew@Eng.Sun.COM New life belongs to Him. Affiliation stated for He hands us each new moment saying, identification purposes only. 'My child, begin again.... You're free to start again.'"