print lines from a file containing key word

i have a file containing over 1 million records,and i want to print about 300,000 line containing a some specific words.

file has content.
eg

1,rrt,234
3,fgt,678
4,crf,456
5,cde,drt
6,cfg,123

and i want to print the line with the word fgt,crf

this is just an example,my file is so huge,i have tried using

grep fgt filename

and

awk '/fgt/' filename

but it is so slow
is there a way where i can get the data faster

For a sequential unsorted search, it doesn't get any faster than doing a simple pattern match. There's just no shortcut.... you could try reading the entire file into memory and searching through that... (just an idea of how you can make it faster by not using the disk).

Alternatively, you can look into a preprocessor for the file that creates indexes into the data (usually means sorting... but there are free-text indexers out there)... man are search engine like indexers... so they just are used to find full files containing matches... but look around... you never know.

Your file data looks like a spreadsheet csv... so maybe importing it as a spreadsheet might give you some advantage (??).

Just some ideas...

you may get a better performance with 'fgrep' (instead of grep).