Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!sunic!lth.se!newsuser From: bengtl@maths.lth.se (Bengt Larsson) Newsgroups: comp.unix.shell Subject: Re: searching for data Keywords: shell script Message-ID: <1991Apr17.211023.17481@lth.se> Date: 17 Apr 91 21:10:23 GMT References: <18dQ01aK5bwe00@amdahl.uts.amdahl.com> Sender: newsuser@lth.se (LTH network news server) Reply-To: bengtl@maths.lth.se (Bengt Larsson) Organization: Lund Institute of Technology, Sweden Lines: 30 In article <18dQ01aK5bwe00@amdahl.uts.amdahl.com> krs@amdahl.uts.amdahl.com (Kris Stephens [Hail Eris!]) writes: >In article cs342a37@cs.iastate.edu >(Class login) writes: >>I am a new comer in writing shell scripts. I have the following problem: >>I have a data file that I use as a key for searching my Master file. [trimmed] >> >>I have the following script written: >> >>cat datafile : ( while read line; do fgrep "$line" masterfile >> >>outputfile ; done ) >> >>This however, is very slow as I have about 2000 lines of key in my >>data file and about 10000 lines of records in my master file, and for >>each key I have to scan about 10000 lines. There was a suggestion using awk. My mail to the original author bounced, and noone else has said this, so how about: fgrep -f datafile masterfile >> outputfile _That_ should be faster (fgrep is optimized for this (looking for a set of fixed strings, that is)). Of course, if I got the problem wrong, someone will point it out :-) Bengt Larsson. -- Bengt Larsson - Dep. of Math. Statistics, Lund University, Sweden Internet: bengtl@maths.lth.se SUNET: TYCHE::BENGT_L