Hi All,

I'm currently working on finding a solution to strip/edit a texfile in order to pass it through to Oracle's SQLLOADER which in turn will import the data into a table.

The textfile will need to be imported into a clob column inside the first table after which the imported data will need to be placed in the proper columns but unfortunately I haven't got a clue as to how I need to start but I think Python is my best bet...

The textfile looks like the first attachment.

Now, what I don't need from the textfile is the header and the last part of the textfile starting from "Summary for fw0204.txt".
What I do need in my database import file is the first part of the textfile containing the 'sort of' columns but is a bit distorted with spaces etc...
It should look like this when 'the' script is done with it and it can be passed on to an sqlloader import file:

The output file needs to look like the last attachment

How do I create a python script to use the above data from the textfile into an inputfile for sqlloader?

You help will be much appreciated, thanks in advance!

cheers

Recommended Answers

All 2 Replies

What I do need in my database import file is the first part of the textfile containing the 'sort of' columns but is a bit distorted with spaces etc...

Perhaps you could describe with words the precise way the lines are 'distorted'. If it can't be described precisely, it can't be programmed ...

Here simple one, if you use Linux or similar, add appropriate Exception type to mkdir except

import os
import webbrowser

def process(fn):
    with open(fn) as infile, open('./output/'+fn, 'w') as outfile:
        outfile.write(next(infile)[:26] + '\n')
        for line in infile:
            if '.txt' not in line:
                break
            else:
                outfile.write(line.rsplit('.txt',1)[0].rsplit(None,1)[0]+'\n')
    webbrowser.open('./output/' + fn)

try:
    os.mkdir('./output')
#add here exception produced in Linux, if you use that
except WindowsError as e:
    print('Directory exists, using existing one')

process('t1.txt')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.