MACRO TO SPLIT BIGFILE;SAVE TEXT EXTRACTS TO SEPERATE FILES

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
MT_MANC
Posts: 10
Joined: Sat May 03, 2008 1:02 pm

MACRO TO SPLIT BIGFILE;SAVE TEXT EXTRACTS TO SEPERATE FILES

Post by MT_MANC »

I have a large .txt (115,000 lines) that contains many variable length sub-sections stacked on top of each other; I need to extract each subsection text between Common seperators & save extraction to a seperate text file (with *.LOG extension). Need to automate process via macro (or other method ?)

For each subsection: ------
Start String: "WinSolve log file created "
End String: "Exit"
File Name to Save Extracted subsection text to: Occurs on Line 3 of each subsection
(eg1 1st subsection Line 3 reads: "@ gRSH1p_u @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
(eg2 2nd subsection Line 3 reads: "@ gOILp_u @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
So 1st subsection => saved to c:\data\ws3\sim\LOGS\gRSH1p_u.LOG
So 2nd subsection => saved to c:\data\ws3\sim\LOGS\gRSH1p_u.LOG


SECTION OF LARGE FILE TO BE SPLIT:------------------
  • WinSolve log file created
    @
    @ gRSH1p_u @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @
    [TRUNCATED SUBSECTION TEXT]
    @
    Exit
    @
    WinSolve log file created
    @
    @ gOILp_u @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @
    [TRUNCATED SUBSECTION TEXT]
    @
    Exit
    @
    WinSolve log file created
    @
    @ gTRX1p_u @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @
    [TRUNCATED SUBSECTION TEXT]
    @
    Exit
    etc
    etc
SUMMARY OF REQUIREMENT
1st subsection, extract all text between "WinSolve log file created " & "Exit" ; save to c:\data\ws3\sim\LOGS\gRSH1p_u.LOG
2nd subsection, extract all text between "WinSolve log file created " & "Exit" ; save to c:\data\ws3\sim\LOGS\gOILp_u.LOG
3rd subsection, extract all text between "WinSolve log file created " & "Exit" ; save to c:\data\ws3\sim\LOGS\gTRX1p_u.LOG
etc
etc
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

I can only help with the first half of the requirement. You can record a macro to split the file into separate documents:

1. Click Macros > Record.
2. Click Search > Find.
3. In Find what, enter ^Exit\n@\n (assuming each subsection ends in "Exit" followed by "@" on a separate line)
4. Select Regular expression.
5. Select Extend selection.
6. Click Find Next.
7. Click Close.
8. Click Edit > Cut.
9. Click File > New.
10. Click Edit > Paste.
11. Click Macros > Stop Recording.

But the hard part is then saving each document with a variable file name. I can't think of a way to do this.
MT_MANC
Posts: 10
Joined: Sat May 03, 2008 1:02 pm

Post by MT_MANC »

Thanks for this
May need to resort to something like Perl (unless you have any other suggestions - WildEdit ?)

MT
pboivin007
Posts: 5
Joined: Tue Sep 28, 2010 1:05 pm

Post by pboivin007 »

You should look at VB Script. You can run a .VBS from the command line, or from textpad tools. Maybe Perl can do the same things, but I don't know Perl.

Set FS = CreateObject("Scripting.FileSystemObject")
Set oFile = FS.OpenTextFile("HugeFile.log", ForReading)
Do While Not objFlagFile.AtEndOfStream
OneLine = oFile.ReadLine
...
Loop
oFile.Close
Set oFile = Nothing
Set FS = Nothing
MT_MANC
Posts: 10
Joined: Sat May 03, 2008 1:02 pm

Post by MT_MANC »

Thank you for this.
Yes, I went doen the Perl route in the end..got their eventually - I can post Perl code on request if anyone needs ?

Thanks again
Post Reply