I have two files. The first file has three hundred thousand records shown example (file1
) and second file has one hundred thousand records, shown example (file2
). I am basically doing a grep of each entry on file2
with file1
and retrieve all that is in file1. I am doing this with a normal for loop:
for i in `cat file2.txt`; do cat file1 | grep -i -w $i; done > /var/tmp/file3.txt
As the data is too huge it takes me 8+ hours to complete this operation.. I need your expertise in giving me an option on how can I do this in an efficient way to deliver this in less than 2-3 hours.
Example entries
File1
server1:user1:x:13621:22324:User One:/users/user1:/bin/ksh |
server1:user2:x:14537:100:User two:/users/user2:/bin/bash |
server1:user3:x:14598:24:User three:/users/user3:/bin/bash |
server1:user4:x:14598:24:User Four:/users/user4:/bin/bash |
server1:user5:x:14598:24:User Five:/users/user5:/bin/bash |
File2
user1
user2
user3