Newsgroups: comp.unix.shell
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!news.cs.indiana.edu!ux1.cso.uiuc.edu!news.iastate.edu!cs342a37
From: cs342a37@cs.iastate.edu (Class login)
Subject: searching for data
Message-ID: <cs342a37.671481248@zaphod>
Summary: Any way to write a shell script to read a file?
Keywords: shell script
Sender: news@news.iastate.edu (USENET News System)
Organization: Iowa State University, Ames IA
Date: 12 Apr 91 18:34:08 GMT
Lines: 29

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. Both files are text files. Each line in the Master file is a record. Both files are sorted by the key. I would like to readaa line in the data file for the key, and then read scan the Master file for the line that contains the key and append that to a file.

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.

Can I write a shell script to do the following:
read a line from masterfile
while more  key to read do
  read a line from data file
  while (key from masterfile < line from data file)
    read line from masterfile
  (end while)
  if line from masterfile contains key
    append to output file
  else
    append empty line to output file
  (endif)
(end while)





