Search for a value in a particular column in a .txt file

0

I am trying to search for a value in a certain position in the column of a text file and generating another file with these lines, but without success

Follow the code:

arquivo = open('arquivo.txt', 'r')
arquivo2 = open('arquivo2.txt', 'w')

for i in arquivo.readlines():
    if i[70:71] == '02':
        arquivo2.write(i)
        print(i.rstrip())



arquivo.close()
arquivo2.close()
    
asked by anonymous 16.11.2018 / 01:48

1 answer

1

You have not been able to tell what happens when you run, if there is an error, or if you have some other problem in the result.

As we do not have the file, only you, can not guess what's happening.

One of the errors you can already see is that you make the comparison i[70:71] == '02' but i[70:71] has only 1 character logo can never be equal to '02' .

Maybe you want to say i[70:72] or i[69:71] because these have 2 characters.

    
16.11.2018 / 02:01