Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.mel.connect.com.au!news.mira.net.au!news.vbc.net!alpha.sky.net!winternet.com!nntp04.primenet.com!news.shkoo.com!nntp.primenet.com!News1.mcs.net!van-bc!unixg.ubc.ca!info.ucla.edu!nnrp.info.ucla.edu!agate!newsxfer2.itd.umich.edu!portc01.blue.aol.com!psinntp!psinntp!psinntp!usenet2.news.uk.psi.net!uknet!usenet1.news.uk.psi.net!uknet!dispatch.news.demon.net!demon!awfulhak.demon.co.uk!awfulhak.demon.co.uk!awfulhak.de mon.co.uk!not-for-mail From: brian@awfulhak.demon.co.uk (Brian Somers) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: sh command shell script writing. i'm stuck Date: 31 Jul 1996 22:13:11 +0100 Organization: Coverform Ltd. Lines: 36 Message-ID: <4toi97$ar@anorak.coverform.lan> References: <4t02d1$nec@cliff.island.net> <Pine.HPP.3.91.960722171415.29481F-100000@lint.cisco.com> <Dv4rGs.2nv@rockyd.rockefeller.edu> NNTP-Posting-Host: localhost.coverform.lan X-NNTP-Posting-Host: awfulhak.demon.co.uk X-Newsreader: TIN [version 1.2 PL2] Dan Ts'o (dan@dnn.rockefeller.edu) wrote: : Others have given you solutions as to how to read in one line at a : time into a script. But these are all a little nasty (because they run awk : or grep, which is pretty big and then that program re-reads the whole file : just to pick out another line). Perhaps you could expand on just what you : are trying to do. There maybe a more efficient way. : For example, how about something like: : ( : while read line : do : # Do whatever : echo "Here is another line: $line" : done : ) < input_file If you're gonna complain about the overhead of awk, why do you put the parenthesis in ? This just loads another shell - for sure. With zsh (I'm told) and ksh (not pdksh), the following is even better: x=1 while read line do test $x -eq TheNumberIWant && { echo $line break } done <input_file The shell will execute everything internally. Of course, you had better not be particular about your whitespace... and don't forget about the "break" - ya don't want to read the whole file - do ya ? -- Brian <brian@awfulhak.demon.co.uk> Don't _EVER_ lose your sense of humour....