Dear All,

 

I'm new to Python and started to use it to search text strings in big
(>500Mb) txt files. 

I have a list on text file (e.g. A.txt) that I want to use as a key to
search another file (e.g. B.txt), organized in the following way:

 

A.txt:

 

Aaa

Bbb

Ccc

Ddd

.

.

.

 

B.txt

 

Bbb

1234

Xxx

234

 

 

I want to use A.txt to search in B.txt and have as output the original
search entry (e.g. Bbb) followed by the line that follows it in the B.txt
(e.g.  Bbb / 1234).

I wrote the following script:

 

 

object = open(B.txt', 'r')

lista = open(A.txt', 'r')

searches = lista.readlines()

for line in object.readlines():

     for word in searches:

          if word in line: 

               print line+'\n'

 

 

 

But from here I only get the searching entry and not the line afterwards, I
tried to google it but I got lost and didn't manage to do it.

Any ideas ? I guess that this is basic scripting but I just started .

 

Best 

 

Afonso

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to