G
G
GranD1K2015-05-05 13:52:53
Text Processing Automation
GranD1K, 2015-05-05 13:52:53

Multiline replacement?

Good day to all!
There is a very large amount of information like:
10,11,12,13,14,15,16,17,18,19,20,21,22 | 3400000300000010000
23,24,25,26,27,28,29,30,31,32,33,34,35 | 3400000300000010000
................................. ... . . .. .. .............. | ....................................
33,34,35,36,37,38,38a, 39,4,40,40a,4a | 3400000300000170000
How can I replace row data into a column, while maintaining a range of 2 columns.
10 | 3400000300000010000
11 | 3400000300000010000 etc.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Kamenev, 2015-05-05
@GranD1K

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
res = open('res.txt', 'w')
with open('file.txt') as lines:
    for line in lines:
        _ = line.splitlines()[0].split(' | ')
        for number in _[0].split(','):
            res.write('%s|%s\n' % (number, _[1]))

G
GranD1K, 2015-05-05
@GranD1K

source is res?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question