Estoy intentando sacar los nif de un fichero de texto con el siguiente formato :
Fichero con.txt
texto dkdkkdkdkdk
Expediente
202002345610854
Subvención
Asunto
texto ldllakdkkdkdkdk
dlldlkfkjfkdj
ldldkfjjf
kdkdkdk :
dkdkfjkdk:
Código expediente
DNI/CIF
Importe Subvencion Concedida
1
2020012727
01234567N
1.500,00 €
2
2020013992
76543210Y
1.620,00 €
3
2020013331
01234567T
1.000,00 €
4
2020013637
01234567A
1.500,00 €
5
2020012875
01234567Q
2.220,00 €
6
2020014315
76543210B
1.860,00 €
7
2020012856
76543210Y
1.000,00 €
8
2020013410
76543210D
1.620,00 €
9
2020014320
76543210E
1.120,00 €
10
2020014090
76543210W
1.000,00 €
11
2020012392
76543210Z
1.980,00 €
12
2020012646
76543210S
1.500,00 €
13
2020013292
76543210K
1.740,00 €
14
2020013743
76543210X
1.500,00 €
Listado pág. 1/49
Puede verificar lsldldkkdkkf dkkdkdkdkkd https://www.dkkdkdkdkkdkdk.com
----
15
2020019759
76543210L
1.500,00 €
etc...
hasta
Listado pág. 49/49
Puede verificar lsldldkkdkkf dkkdkdkdkkd https://www.dkkdkdkdkkdkdk.com
texto legal... etc... etc
----
El código que he intentado es el siguiente pero aunque no me da errores tampoco extrae la información que quiero
#! /usr/bin/python3
# _*_ coding: utf-8 _*_
import re
patron = '([0-9]{8})([A-Z]{1})'
input_path = "con.txt"
output_path = "nif.txt"
with open(input_path, "r") as in_file,\
open(output_path, "w") as out_file:
for line in in_file:
lista = re.findall(patron, line)
if lista:
print(lista)
else:
print('zer0 nif')
out_file.write(line)