By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

efficient searching methods than grep

P: 10
hi !

I have two big files like A anb B.
A contains nearly 1000 lines.
and B contains 1500000 lines.





suppose
A contains like
cat mat things go jhf
hem can do that
meant that like this

B contains like

apple come into
do you know that
dog can you lop fhyr jsoe flfj dlfj fjhff fldgfjgj fgjfgklgklf gfhi sjkdhd
did got jdhsh dkjdh sdsdj dskdsjd dlsd sdlsdks dsld dsldsdk uiop
till that dhjhd kdhdhs djlldkjsd ldjdj dlsjkd sdljds dsldjsdslkdjs
home has the growing kljdf dflkdfjkl fjdklfj lkfjdfjopre dfjknf lfjkf dfl
pop mat djhd djkhsd jdd dilieuwue euwe eiuwe weoieuwe ieweue


result:
you lop fhyr jsoe flfj dlfj fjhff fldgfjgj fgjfgklgklf gfhi sjkdhd
dhjhd kdhdhs djlldkjsd ldjdj dlsjkd sdljds dsldjsdslkdjs
djhd djkhsd jdd dilieuwue euwe eiuwe weoieuwe ieweue

Now i want to retrive the second field of A .
and match that field in B and retrive the data after the matching pattern
in that respective line.

I did this by using grep but as the second file is very large it is taking more time to search that line.


Can any one suggest another efficient method for this in perl ?

thanks and regards,
Manogna.
Jan 18 '08 #1
Share this Question
Share on Google+
3 Replies


KevinADC
Expert 2.5K+
P: 4,059
grep searches for all instances of the search pattern in the list/file you grep. So if you need to check for all the matches then grep should be OK. If not, open and process the file line by line and break out of the process when you find the first match or however many matches you need. Generic example:

Expand|Select|Wrap|Line Numbers
  1. open(FH, 'file')
  2. while(<FH>) {
  3.    if (/foo/) {
  4.       print;
  5.       last;
  6.    }
  7. }
  8. close FH;
Jan 18 '08 #2

P: 10
thank you!


But this also taking more time. As the file is very big.


can u suggest any other method?


thanks and regards,
Manogna.
Jan 21 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
post your perl code
Jan 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.