-1

I have a giant text document that looks sort of like this:

A,1,2,3
B,2,5,3
C,7,9,0
.
.
.

How would I write a program that would make the text document look like this:

1 2 3
2 5 3
7 9 0
.
.
.

(Basically the letters and the commas after the letter are removed, and all commas after the first number change into spaces)

M. Chak
  • 530
  • 3
  • 13

2 Answers2

1

You'll want to call the following on each line:

line.split(',')[1:]

This splits the line along the commas, and then slices off the first element.

alexgolec
  • 26,898
  • 33
  • 107
  • 159
0

If you're on Linux/Unix you can use basic shell commands, which should be available everywhere:

cut -d "," -f 2- --output-delimiter=" " input.txt > output.txt

If you insist on using Python, you can do:

with open('input.txt', 'r') as infile, open('output.txt', 'w') as outfile:
    for line in infile:
        outfile.write(' '.join(line.split(',')[1:]))
Jan Christoph Terasa
  • 5,781
  • 24
  • 34