Grep multiple terms and output to individual files

Hi all,

I'll like to search a list of tems in a huge file and then output each of the terms to individual files. I know I can use grep -f list main.file to search them but how can I split the output into individual files? Thank you.

Can you be more specific with some examples...

Try with while loop.

For example, the following are the term in my list file:

LR30F04
LW36F03
PI21M21

And I'll like to grep all lines containing LR30F04 into file1.txt, LW36F03 into file2.txt, etc...

Thank you.

---------- Post updated at 12:50 PM ---------- Previous update was at 12:42 PM ----------

Can you elaborate? Sorry, I'm a biologist trying to do some data manipulation here.

I guess pamu was refering to below code

$ while read line
 do
 let count=$count+1
 grep -w $line input_file > file${count}
 done < term_file

1 Like

What about:

while IFS= read -r pattern; do grep $pattern hugefile >$pattern.txt & done <mylistfile; wait; echo "I'm done"

--
Bye

This is working for me. Thank you all for your help.