Here is my code I want to search and replace three strings
tmp="/tmp"
day = datetime.date.today().day
today = datetime.date.today()
year =datetime.date.today().year
month = today.strftime('%b')
f1 = open("%s/backup.txt" % (tmp), 'r')
f2 = open("%s/backup1.txt" % (tmp), 'w')
for line in f1:
f2.write(line.replace('day', "%s" % (day)))
f1.close()
f2.close()
f1 = open("%s/backup1.txt" % (tmp), 'r')
f2 = open("%s/backup2.txt" % (tmp), 'w')
for line in f1:
f2.write(line.replace('mon', "%s" % (mon)))
f1.close()
f2.close()
f1 = open("%s/backup2.txt" % (tmp), 'r')
f2 = open("%s/backup3.txt" % (tmp), 'w')
for line in f1:
f2.write(line.replace('year', "%s" % (year)))
f1.close()
f2.close()
Anyway to do this in a single shot and by reducing the LOC?
I want to search and replace year, mon and day in single shot Regards,