I need to add a line break to every single line of text
I have changed a CSV file to a text file, in that text file I need to add a line break at the end of every line/sentance
I can only manage currently to add a single line break on the first line of text, I can not work out how to do it for subsequent lines
An example of what I have when I change the CSV file to Txt:
Device_1 A 10.0.0.1
Device_2 A 10.0.0.2
Device_3 A 10.0.0.3
An example of what I want it to look like
Device_1 A 10.0.0.1
Device_2 A 10.0.0.2
Device_3 A 10.0.0.3
An example of what it actually looks like after the python script runs
Device_1 A 10.0.0.1
Device_2 A 10.0.0.2
Device_3 A 10.0.0.3
The code I have tried:
import shutil
source = 'DNS_Entries.csv'
target = 'DNS_Entries_Copy.txt'
shutil.copy(source, target)
def DNS_Entries(self,DNS):
with open(DNS) as f:
lines = [line+'\n' for line in f.readlines()]
with open(DNS+'DNS_Entries_Copy.txt', 'w') as f:
f.write(''.join(lines))
I have also tried:
import shutil
source = 'DNS_Entries.csv'
target = 'DNS_Entries_Copy.txt'
shutil.copy(source, target)
def DNS_Entries(self,DNS):
with open(DNS) as f:
lines = [line+'\n' for line in f.readlines()]
with open(DNS) as source:
with open(DNS+'DNS_Entries_Copy.txt', 'w') as output:
for line in source:
f.write(line+'\n')
Both of the above scripts add a single line break at the end of the first line of text.
Unfortunately its never the same number or character at the end of the line to reference and each line can differ with the amount of characters/numbers per line.
Thanks