best way to divide a text doc in two?

User avatar
stuck
Panoramic Lounger
Posts: 8176
Joined: 25 Jan 2010, 09:09
Location: retirement

best way to divide a text doc in two?

Post by stuck »

I have some .txt files that are of indeterminate length but always have a defined structure, usually one section but frequently two sections and ocasionally thre or more. If the files are 'multiple' files then I need to divide them at a known points. At the moment for a simple divide in two I:
- open the files in WordPad
- scroll to the split point
- delete everything below
- save as (retaining the .txt format)
- re-open the original file
- scroll to the split point
- delete everything above
- save as (retaining the .txt format)

There's got to be an easier way.

By the way, the reason I split these 'multiple files into 'single' files is so that all behave in the same way when they are read by an Excel macro and imported into a spreadsheet. This subsequent use does suggest that splitting the txt files before import is still over intense and that the more logical solution is to rewrite the Excel import macro to cope when the txt files have more than one section but it's nearly Christmas and that sounds like a lot of effort best left to the new year.

Thanks,

Ken
Last edited by HansV on 19 Dec 2014, 16:12, edited 1 time in total.
Reason: typo in subject

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: best way to divide a text doc in two?

Post by HansV »

If you can specify precisely what constitutes a "split point", it would be possible to write a macro that splits the text files.
You could dump all text files in a folder, and let the macro process all files in that folder, or display a multi-select "Open" dialog, and process only the selected files.
Best wishes,
Hans