Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input.txt
- ...text... <!-- 140101002 --> ...text...
- ...text... <!-- 140101030 --> ...text...
- ...text... <!-- 140101004 --> ...text...
- ...text... <!-- 140101058 --> ...text...
- ...text... <!-- name44 --> ...text...
- ...text... <!-- name2 --> ...text...
- ...text... <!-- name3 --> ...text...
- ...text... <!-- name94 --> ...text...
- fhand = open("/home/Documents/input.txt")
- template = open("/home/Documents/template.txt")
- fout = open("/home/Documents/output.txt","w")
- # store the values in the dictionary:
- templateDict = dict()
- for line in template:
- lineList = line.split("t")
- templateDict[lineList[0]] = lineList[1]
- # replacement:
- for line in fhand:
- for key in templateDict:
- if key in line2:
- line2 = line2.replace(key,templateDict[key])
- fout.write(line2) # write to output.txt
- fout.close()
- import re
- d = dict(re.split('s+', i.strip('n')) for i in open('filename.txt'))
- content = [i.strip('n') for i in open('filename2.txt')]
- with open('results.txt', 'w') as f:
- f.write('n'.join(re.sub('(?<=<!--s)d+(?=s-->)', lambda x:d[x.group()], i) for i in content))
- ...text... <!-- name44 --> ...text...
- ...text... <!-- name2 --> ...text...
- ...text... <!-- name3 --> ...text...
- ...text... <!-- name94 --> ...text...
Add Comment
Please, Sign In to add comment