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
Am I missing something, or why not just fgrep -f "$sourcefile" "$targetfile"
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With