Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!edcastle!spider!raft.spider.co.uk!mark From: mark@spider.co.uk (Mark Valentine) Newsgroups: comp.unix.shell Subject: Re: How to read sequentially from a file in SH (not KSH) Message-ID: <1991Apr29.105329.20148@spider.co.uk> Date: 29 Apr 91 10:53:29 GMT References: <1991Apr27.012336.2732@shibaya.lonestar.org> <232@bria.UUCP> Sender: news@spider.co.uk (USENET News System) Organization: Spider Systems Limited, Edinburgh, UK. Lines: 27 Nntp-Posting-Host: redknee.spider.co.uk afc> while read VAR1 VAR2 < $FILENAME; do afc> echo $VAR1 $VAR2 afc> done afc> afc> but I keep reading the first line in the file over and over. Nothing in afc> the manual page seems to be usable in this situation. How is this done afc> under SH? Is it possible? mike> cat $FILENAME | while read VAR1 VAR2 mike> do echo $VAR1 $VAR2 mike> done Sometimes this doesn't fit into the logic of a shell script. In such cases I find that something like following works nicely. exec 3< $FILENAME while read VAR1 VAR2 <&3 do echo $VAR1 $VAR2 done This is especially handy if you have a couple of files you're reading simultaneously in the body of the loop, or the conditional isn't based on the read itself. Mark. -- Mark Valentine, Spider Systems /\oo/\