data = data2 = "";
# Reading data from file1
with open('sample1.txt') as fp:
data = fp.read()
# Reading data from file2
with open('sample2.txt') as fp:
data2 = fp.read()
# Merging 2 files
# To add the data of file2
# from next line
with open ('sample3.bat', 'a') as fp:
fp.writelines("KeyHunt-Cuda -m address --coin btc --range " + data + ":" + data2 + "13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so" '\n')
Output on above code
KeyHunt-Cuda -m address --coin btc --range aaaa
bbbb
cccc:ddd
eee
fff13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so
File 1
aaaa
bbbb
cccc
File 2
ddd
eee
fff
I hoped the output would be like
KeyHunt-Cuda -m address --coin btc --range aaaa:ddd 13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so
KeyHunt-Cuda -m address --coin btc --range bbbb:eee 13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so
KeyHunt-Cuda -m address --coin btc --range cccc:fff 13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so
How should I change the code?
>Solution :
Use readlines() to read each file into a list of lines. Then loop over the lines to produce the output you want.
# Reading data from file1
with open('sample1.txt') as fp:
data = fp.readlines()
# Reading data from file2
with open('sample2.txt') as fp:
data2 = fp.readlines()
with open ('sample3.bat', 'a') as fp:
for line1, line2 in zip(data, data2):
fp.write(f"KeyHunt-Cuda -m address --coin btc --range {line1.strip()}:{line2.strip()} 13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so\n")