Optimizing grep (or using AWK) in a shell script

Posted by Ode on Stack Overflow See other posts from Stack Overflow or by Ode
Published on 2010-05-12T17:16:01Z Indexed on 2010/05/12 18:44 UTC
Read the original article Hit count: 110

Filed under:
|
|

Hi -

In my shell script, I am trying to search using terms found in a $sourcefile against the same $targetfile over and over.

My $sourcefile is formatted as such:

pattern1
pattern2
etc...

The inefficient loop I have to search with is:

for line in $(< $sourcefile);do
    fgrep $line $targetfile | fgrep "RID" >> $outputfile
done

I understand it would be possible to improve this by either loading the whole $targetfile into memory, or perhaps by using AWK?

Thanks

© Stack Overflow or respective owner

Related posts about grep

Related posts about awk