Copy filtered lines to clipboard via macro

Copy filtered lines to clipboard via macro

1
NewbieNewbie
1

    Apr 13, 2018#1

    I recently upgraded to the anniversary edition (version 25.00.0.68) and tried out the new "Filter Lines" feature in "Find and Replace." I was able to show only the lines with the text listed in the "find what" field, but I want to copy just those lines into the clipboard to paste into another application. When I try copying just the displayed lines, the entire contents of the file is placed into the clipboard instead. As a workaround, I managed to bookmark each of the resulting filtered lines, copy all bookmarked lines to the clipboard, and paste it into the external application. However, manually bookmarking the lines is not feasible when there is a large number of results. Also since I would ultimately like to put this process into a macro, it poses a challenge as the number of lines needed to bookmark is unknown.

    What is the best way to manually copy only the filtered lines resulting from the search to the clipboard, and is there any recommendation on how I might script this process it into a macro?

    Thank you in advance for any advice!

    BSOD76

    Supporting information:

    Here is an example of the original file being searched:

    Code: Select all

    <Redacted Text>
    RECORDS PROCESSED:                      14
    RECORDS UPDATED:                        14
    <Redacted Text>
    RECORDS PROCESSED:                      15
    RECORDS UPDATED:                        15
    <Redacted Text>
    # SELECTED 403
    NOW PROCESSING...
    400 PROCESSED
    RECORDS PROCESSED:                     403
    RECORDS UPDATED:                       403
    <Redacted Text>
    NOW PROCESSING...
    800 PROCESSED
    RECORDS UPDATED:                       879
    Desired Results ultimately copied to the clipboard to paste in an external application:

    Code: Select all

    RECORDS UPDATED:                        14
    RECORDS UPDATED:                        15
    RECORDS UPDATED:                       403
    RECORDS UPDATED:                       879

    11327
    MasterMaster
    11327

      Apr 13, 2018#2

      In Find dialog check List lines containing string and press next.

      In Find String List invoke context menu (right mouse button click) and choose desired action.

      HTH
      It's impossible to lead us astray for we don't care even to choose the way.

      6,680583
      Grand MasterGrand Master
      6,680583

        Apr 14, 2018#3

        Copying all lines containing a string to clipboard or a new file is a very often asked task and can be done in many different ways.
        1. Use Find with option List lines containing string and copy the found and listed lines to clipboard via context menu command Copy to clipboard or Copy results to new file as posted already by Ovg.
           
        2. Use Find in Files with option In set to Open files and option Results to edit window checked to get the results written into a new file or with this option not checked to write the results in active output window and use context menu item Copy to clipboard. The results output format can be customized at Advanced - Settings or Configuration - Search - Find output format to get just the found lines output with having only Found line checked with $S as format string.
           
        3. One of the scripts from Find strings with a regular expression and output them to new file like FindStringsToNewFile.js can be added to Script list by clicking with using ribbon mode on ribbon tab Advanced in ribbon group Script on item All scripts and then click on down arrow of item Play script to open the popup menu containing FindStringsToNewFile.js to run it on active file with search string RECORDS UPDATED.+ It is also possible to check on ribbon tab Layout in group Views the item Script list and double click on FindStringsToNewFile.js.
           
        4. Another possibility would be using one of the posted macros to copy all lines containing a string to clipboard or a new file like Search string and copy all found lines/strings to clipboard or new file adapted to different search string:

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          Bottom
          IfColNumGt 1
          "
          "
          IfColNumGt 1
          DeleteToStartofLine
          EndIf
          EndIf
          Top
          ClearClipboard
          Loop 0
          UltraEditReOn
          Find MatchCase RegExp "%RECORDS UPDATED:*^p"
          IfFound
          CopyAppend
          Else
          ExitLoop
          EndIf
          EndLoop
          Top
          
        5. It is also possible to use a macro to copy first all lines to a new file, then delete all lines not starting with the string RECORDS UPDATED, copy all remaining lines to clipboard and close the new file without saving it.

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          SelectAll
          Copy
          NewFile
          Paste
          IfColNumGt 1
          InsertLine
          IfColNumGt 1
          DeleteToStartofLine
          EndIf
          EndIf
          Top
          PerlReOn
          Find MatchCase RegExp "^(?!RECORDS UPDATED).*[\r\n]+"
          Replace All ""
          SelectAll
          IfSel
          Copy
          Else
          ClearClipboard
          EndIf
          CloseFile NoSave
          
        6. It is also possible to copy all lines of file with Ctrl+A, Ctrl+C, Ctrl+N, Ctrl+V to a new file, use Find with Filter lines enabled and Show selected, click next on ribbon tab Edit in first group Select and delete on down arrow below item Delete and use from popup menu Delete all hidden lines.
        But selecting and copying just displayed lines after using Find with Filter lines enabled and Show selected is not possible. There is no command to select just the lines currently shown.
        Best regards from an UC/UE/UES for Windows user from Austria

        1032
        Power UserPower User
        1032

          Apr 19, 2018#4

          Good solutions for the task when the user wants to find some string.
          But what about the case when we need to copy only the filtered lines shown with code folding collapsed?
          Like this example:
          code folding.png (57.96KiB)
          I want to send to Clipboard only lines 57 and 71, but if I press CTRL-C or menu Edit/Copy, all lines between 57 and 82 are copied.
          How to copy only those 2 lines 57 and 71?

          Edit 10 minutes later:
          Mofi wrote:
          1. It is also possible to copy all lines of file with Ctrl+A, Ctrl+C, Ctrl+N, Ctrl+V to a new file, use Find with Filter lines enabled and Show selected, click next on ribbon tab Edit in first group Select and delete on down arrow below item Delete and use from popup menu Delete all hidden lines.
          Sorry, I just saw that recommendation about ribbon tab Edit - Delete all hidden lines. I always use traditional menu and it looks like there are too many features only on ribbon mode thus I'm not aware of them.

          It works very well.
          But if there are other solutions, without need to modify the current file (deleting lines), I'd love to know/learn.

          Edit by Mofi: See Missing commands in toolbar/menu mode with traditional menu regarding to missing features on using traditional menus.