Splitting text file

Splitting text file

3
NewbieNewbie
3

    Sep 11, 2006#1

    I am looking for a program I can use to split up text files between patterns. Like

    Code: Select all

    -*-
    Line 1
    Line 2
    -*-
    Line 3
    Line 4
    I would want lines 1 and 2 in one file, and line 2 and 3 in another...Using "-*-" to tell it where to break up the files.

    Is there A) an easy way to do this or B) a macro already written for this?

    6,675585
    Grand MasterGrand Master
    6,675585

      Sep 11, 2006#2

      The following macro should do the job according to your example. The macro property Continue if a Find with Replace not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      Bottom
      IfColNum 1
      Else
      "
      "
      EndIf
      Top
      Clipboard 9
      Loop
      StartSelect
      Find Select "-*-"
      IfSel
      Key HOME
      EndSelect
      IfSel
      Copy
      NewFile
      Paste
      NextWindow
      EndIf
      Key DOWN ARROW
      Else
      SelectToBottom
      IfSel
      Copy
      NewFile
      Paste
      NextWindow
      EndIf
      EndSelect
      Top
      ExitLoop
      EndIf
      EndLoop
      ClearClipboard
      Clipboard 0

      The macro would be much easier if the source file would look like:

      Line 1
      Line 2
      -*-
      Line 3
      Line 4
      -*-
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        Sep 11, 2006#3

        Looks like its working, then after getting about half way it tells me it can't create temp file. Anyway I could save those out as it comes along? (I just got this program, I know nothing.)

        And I can format it so that it works that way (with the -*- at the end of the text)?

        6,675585
        Grand MasterGrand Master
        6,675585

          Sep 11, 2006#4

          Well, the macro would be only easier with -*- at end of the text if there is never something like that:

          Line 1
          Line 2
          -*-
          -*-
          Line 3
          Line 4

          2 -*- in sequence and no -*- at the end of the file. The macro as is works for all 3 examples. So no need to change the format of the source file.

          I have never seen a problem with temp file creation. How many temp files are created during macro execution? Maybe it would be better to also automatically save and close the new files with an automatically increasing number in the filename.
          Best regards from an UC/UE/UES for Windows user from Austria

          3
          NewbieNewbie
          3

            Sep 11, 2006#5

            It made a little over 100 then pooped out. I think your right though, if there was a way to save and close the files as they where being created it would work flawlessly

            6,675585
            Grand MasterGrand Master
            6,675585

              Sep 11, 2006#6

              Okay! For auto saving the new files with an increasing number you must FIRST create my universal CountUp macro. The source code with description can be found at counter.

              THEN modify the existing macro with this new code. You have to adapt the red highlighted filename with path. If you think you will not produce more than 999 files, you can modify all 0000 to 000.

              InsertMode
              ColumnModeOff
              HexOff
              Bottom
              IfColNum 1
              Else
              "
              "
              EndIf
              Top
              NewFile
              "0000"
              SelectAll
              Clipboard 8
              Copy
              CloseFile NoSave
              Clipboard 9
              Loop
              StartSelect
              Find Select "-*-"
              IfSel
              Key HOME
              EndSelect
              IfSel
              Copy
              Key DOWN ARROW
              NewFile
              Paste
              Top
              "F:\Temp\Test_0000.tmp
              "
              Key UP ARROW
              Find "0000"
              Clipboard 8
              PlayMacro 1 "CountUp"
              Key HOME
              StartSelect
              Key END
              Clipboard 9
              Copy
              EndSelect
              DeleteLine
              SaveAs "^c"
              CloseFile
              Else
              Key DOWN ARROW
              EndIf
              Else
              SelectToBottom
              IfSel
              Copy
              NewFile
              Paste
              Top
              "F:\Temp\Test_0000.tmp
              "
              Key UP ARROW
              Find "0000"
              Clipboard 8
              PlayMacro 1 "CountUp"
              Key HOME
              StartSelect
              Key END
              Clipboard 9
              Copy
              EndSelect
              DeleteLine
              SaveAs "^c"
              CloseFile
              EndIf
              EndSelect
              Top
              ExitLoop
              EndIf
              EndLoop
              Clipboard 9
              ClearClipboard
              Clipboard 8
              ClearClipboard
              Clipboard 0
              Best regards from an UC/UE/UES for Windows user from Austria