I need to find a way to add a new line after a certain string within a text file.
discount_percent :20
discounted :true
final_price :1199
id :893850
name : THELONGING
original_price :1499
discount_percent :40
discounted :true
final_price :119
id :1476450
name : CyberHentai
original_price :199
discount_percent :30
discounted :true
final_price :139
id :1478030
name : MamboWave
original_price :199
discount_percent :15
discounted :true
final_price :84
id :1506230
name : BigfootForest
original_price :99
discount_percent :40
discounted :true
final_price :59
id :1502600
name : AlienX
original_price :99
Here I have a .txt file and I need a way to add a new line after any line containing 'original_price' and the price/ numbers after it.
there is probably an easy solution to this but I can't seem to figure this out, and I have practically 0 knowledge of how to use Regex
I have tried the following:
def fixSpacing():
file1 = open('data.txt', 'w')
file2 = open('tempdata.txt', 'r+')
for line in file2.readlines():
if line.startswith('original_price :'):
But I couldn't think of a way to add a new line after the numbers for price.