searching for data

Bengt Larsson bengtl at maths.lth.se
Thu Apr 18 07:10:23 AEST 1991


In article <18dQ01aK5bwe00 at amdahl.uts.amdahl.com> krs at amdahl.uts.amdahl.com 
(Kris Stephens [Hail Eris!]) writes:
>In article <cs342a37.671481248 at zaphod> cs342a37 at 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 at maths.lth.se             SUNET:    TYCHE::BENGT_L



More information about the Comp.unix.shell mailing list