I have a file with more than 40.000 lines (file1) and I want to extract the lines matching patterns in file2 (about 6000 lines). I use grep like this, but it is very slow: <
Try grep -Fwf file2 file1 > out
grep -Fwf file2 file1 > out
The -F option specifies plain string matching, so should be faster without having to engage the regex engine.
-F