awk pattern match by looping through search patterns

Hi
I am using Solaris 5.10 & ksh

Wanted to loop through a pattern file by reading it and passing it to the awk to match that value present in column 1 of rawdata.txt , if so print column 1 & 2 in to Avlblpatterns.txt. Using the following code but it seems some mistakes and it is running for more time and repeatedly printing the matching pattern.. I think like Cartesian loop. Please correct me where I am wrong. Input pattern 1000 lines and data file will be containing 20000 records.

 
while read line

do

 awk -F"," '{

 if ( $1 == "'$line'" ){print $1,$2}

}' rawdata.txt >> Avlblpatterns.txt

 done < searchpat.txt


---------- Post updated at 11:43 AM ---------- Previous update was at 11:36 AM ----------

Not shared sample files. Please use your own

And how would you like you tea served, Sir?

Running awk a thousand times is far from being efficient. If you skim through these forums, you'll find many posts dealing with (and solving) exactly your or very similar problems.

1 Like

Although I agree that there are plenty of solutions already on the board, does your file searchpat.txt have a blank line in it or some other line that will match multiple lines?

Perhaps you can better manage your requirement with a grep and a cut. Look at the -f flag in the grep manual page to see if that helps.

Robin