Select and copy block of text

Select and copy block of text

33
Basic UserBasic User
33

    Feb 24, 2006#1

    I have many block of text:

    ...
    H046A112020000043728QZIS_U_BI_BILL_1 PRINTER JZVW01RP...
    ...
    DARCH-SAP_DOC_ID
    xxx
    ...
    CRDI-CONTROL %%LINES-END ZET_TYP_PATA TEXT ST SK
    ...


    Value "xxx" is number and is changing in each block.

    I find "xxx" (for example "123456789" (in line DARCH-SAP_DOC_ID) and I want to select and copy complete block of text to new file.

    6,675585
    Grand MasterGrand Master
    6,675585

      Feb 25, 2006#2

      I think, nobody has understand what you want. Could you please extend your example with a bit more information?

      What is your search string? Is the block only a single line where only a simple regular expression is needed or a real block with multiple lines? Do you want each block found copied into a new file or all blocks with that search string copied together (with CopyAppend) to a new file? Should the macro only split the source file blockwise to new files or do you want a block extraction macro?
      Best regards from an UC/UE/UES for Windows user from Austria

      33
      Basic UserBasic User
      33

        Feb 27, 2006#3

        Block of text has about 500 lines and starting with string "H046A112020000043728QZIS_U_BI_BILL_1 PRINTER JZVW01RP" and ending with string "CRDI-CONTROL %%LINES-END ZET_TYP_PATA TEXT ST SK".
        In each block is only one line (unique) DARCH-SAP_DOC_ID with number of block.
        In file is about 5000 block.

        I have list of numbers of blocks (about 200), and I want to have each block of text from this list in separate file.

        I use command "Find (ALT F3)" to find number of block - I jump "in the midle" of block (to line DARCH-SAP_DOC_ID ...).
        I need the macro, wich select complete block of text and copy to new file.

        6,675585
        Grand MasterGrand Master
        6,675585

          Feb 27, 2006#4

          Aha! Now I understand. This is no problem. Use this universal macro with macro property Continue if a Find with Replace not found enabled.

          InsertMode
          ColumnModeOff
          HexOff
          Clipboard 9
          Find Up "^p^p"
          IfNotFound
          Top
          Else
          EndSelect
          Key HOME
          EndIf
          StartSelect
          Find Select "^p^p"
          IfSel
          Key UP ARROW
          Else
          SelectToBottom
          EndIf
          Copy
          EndSelect
          NewFile
          Paste
          ClearClipboard
          Clipboard 0

          Or use this more specialized version of the macro which allows blank lines inside the block and does not need a blank line before a new block starts:

          InsertMode
          ColumnModeOff
          HexOff
          Clipboard 9
          Find Up "H046A112020000043728QZIS_U_BI_BILL_1 PRINTER JZVW01RP"
          IfNotFound
          Top
          Else
          EndSelect
          Key HOME
          EndIf
          StartSelect
          Find Select "CRDI-CONTROL %%LINES-END ZET_TYP_PATA TEXT ST SK"
          IfSel
          Key END
          Else
          SelectToBottom
          EndIf
          Copy
          EndSelect
          NewFile
          Paste
          ClearClipboard
          Clipboard 0
          Best regards from an UC/UE/UES for Windows user from Austria

          33
          Basic UserBasic User
          33

            Feb 27, 2006#5

            Thank you very much! Second version works very well.

            But would be perfect, when macro could read from list of numbers of blocks (second text file in the same directory), find relevant block and do it all for every number of list. Every separate file should by saved in same directory with the name "number.txt".

            Mayby I too choosy ...

            6,675585
            Grand MasterGrand Master
            6,675585

              Feb 28, 2006#6

              To extend the macro to do everything is no real problem. I just need the information, how the numbers are formated in the second file. 1 number per line or the numbers separated by space or an other character?

              I assume, that there is 1 number per line and nothing else is in a line. You should only have open 2 files: The first file is your large file with the blocks. The second files contains the numbers. The second file has the focus.

              Then run this macro with macro property Continue if a Find with Replace not found enabled. If a number is not found in the first file, this number is marked with "Not found ->" in the file with the list of numbers.

              Note: First copy this macro to a normal edit window and use Trim Trailing Spaces to remove the spaces at end of the line caused by HTML format. Then select the code again and copy it to the edit macro dialog. This is important because of the 2
              "
              "
              sequences where no space should be at end of first ".

              InsertMode
              ColumnModeOff
              HexOff
              Bottom
              UnixReOff
              IfColNum 1
              Else
              "
              "
              EndIf
              Top
              TrimTrailingSpaces
              Loop
              IfEof
              ExitLoop
              EndIf
              Clipboard 8
              SelectWord
              IfSel
              Copy
              EndSelect
              Key HOME
              NextWindow
              Top
              Find MatchCase RegExp "DARCH-SAP_DOC_ID 0++^c"
              IfFound
              Clipboard 9
              Find Up "H046A112020000043728QZIS_U_BI_BILL_1 PRINTER JZVW01RP"
              IfNotFound
              Top
              Else
              EndSelect
              Key HOME
              EndIf
              StartSelect
              Find Select "CRDI-CONTROL %%LINES-END ZET_TYP_PATA TEXT ST SK"
              IfSel
              Key END
              Else
              SelectToBottom
              EndIf
              Copy
              EndSelect
              NewFile
              Clipboard 8
              Paste
              ".txt"
              SelectToTop
              Cut
              Clipboard 9
              Paste
              "
              "
              Clipboard 8
              SaveAs "^c"
              CloseFile NoSave
              PreviousWindow
              Else
              PreviousWindow
              "Not found -> "
              EndIf
              EndIf
              EndSelect
              Key HOME
              Key DOWN ARROW
              EndLoop
              Clipboard 8
              ClearClipboard
              Clipboard 9
              ClearClipboard
              Clipboard 0
              UnixReOn

              Remove the last red command, if you use regular expression in UltraEdit style by default instead of Unix style.
              For UltraEdit v11.10c and lower see Advanced - Configuration - Find - Unix style Regular Expressions.
              For UltraEdit v11.20 and higher see Advanced - Configuration - Searching - Unix style Regular Expressions.
              Macro commands UnixReOn/UnixReOff modifies this setting.
              Best regards from an UC/UE/UES for Windows user from Austria

              33
              Basic UserBasic User
              33

                Feb 28, 2006#7

                I have two files - big one "RDI.txt" and second one "list_rdi.txt". In list_rdi.txt is list of numbers - 1 number per line.
                I opened olny these two files and second file has the focus.
                I run this macro with macro property "Continue if a Find with Replace not found enabled".
                All numbers from list_rdi.txt are RDI.txt.
                But when I run macro, all numbers in list_rdi.txt are marked with "Not found ->" and nothing else...
                What is the problem?

                344
                MasterMaster
                344

                  Feb 28, 2006#8

                  Oh dude, zero points.

                  You have:
                  DARCH-SAP_DOC_ID 007401015482
                  not
                  DARCH-SAP_DOC_ID 7401015482
                  as expected.

                  Change the input file to 007401015482 and it works.

                  rds Bego
                  Normally using all newest english version incl. each hotfix. Win 10 64 bit

                  6,675585
                  Grand MasterGrand Master
                  6,675585

                    Feb 28, 2006#9

                    Thanks, Bego!

                    I have modified the search string in my macro code now to a regular expression string where leading 0s are allowed before the DOC_ID number from the list file. See green and red highlighted parts and the new last paragraph after the macro code at my previous post.
                    Best regards from an UC/UE/UES for Windows user from Austria

                    344
                    MasterMaster
                    344

                      Mar 01, 2006#10

                      Hi Mofi,

                      sure even better :-), didnt have much time yesterday ...

                      I think ultra has to send you some beer ;-)

                      rds Bego
                      Normally using all newest english version incl. each hotfix. Win 10 64 bit