I have a text file with some of the rows containing data as below. I want to replace rows matching these patterns by adding more space in the beginning (i.e. currently these rows having 14 Space which I want to make 34).
I can not just replace 14 Spaces to 34 as there are other rows as well with 14 Spaces but not matching below pattern.
9
1P
PKC
ABC1
1BC1C
ZBC12X
A4C12XZ
H4C12XZQ
94C12XZQQ
Q4C12XZQQT
A4C12XZQQTY
I am using all 11 individual code to search for this 11 pattern as below:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z]$
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z]$
Below is the Python code I'm using.
import re
input_file = open("1.txt", "r")
for line in input_file:
if re.match('[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z][0-9,A-Z]$', line):
print (line)
I need guidance on how I can replace the text now to get below output. I can use re.Sub but then how I can just add the spaces and not replace the other character in the original line which should be used just for matching pattern.
Output:
9
1P
PKC
ABC1
1BC1C
ZBC12X
A4C12XZ
H4C12XZQ
94C12XZQQ
Q4C12XZQQT
A4C12XZQQTY