python - How to split a text file into multiple text files -
here text file.
oh , yeah , got puppy . idea . elliot looks little green . no . and contains many lines.
i want split file 2 text file way using python or other ways being able use in linux.
input.txt :
oh , yeah , got puppy . elliot looks little green . response.txt:
this idea . no . so, 2 text files; 1 has odd-numbered line, other has even-numbered line. how can do?
try this:
with open("your_file") f, open("input.txt", "w") inp, open("output.txt", "w") out: i,line in enumerate(f): if (i+1)%2 == 0: out.write(line) else: inp.write(line)
Comments
Post a Comment