Is there a way to CUT the lines that matched a find and paste them into another file?

Is there a way to CUT the lines that matched a find and paste them into another file?

5
NewbieNewbie
5

    Apr 26, 2019#1

    I can use filter/show to display only the lines that I want, but if I try to select all & cut them it seems to grab all of the folded lines as well.

    I can do a multi-line copy and paste pretty easily, but I haven't figured out a way to do the cut.

    Thanks.

    19176
    MasterMaster
    19176

      Apr 28, 2019#2

      Hi, you cannot CUT them directly but you can delete them.

      Step by step from the very beginning:
      • In Find dialog
        check List lines containing string and
        check Filter lines with selecting Hide.
      • Click on buttonNext.
      • Do Copy to clipboard or Copy results to new file from Find String List context menu.
        (I thought that Copy to clipboard copies just one line from Find String List though it copies everything.)
      • Do Edit / Delete / Delete all hidden lines.
      BR, Fleggy

      6,687586
      Grand MasterGrand Master
      6,687586

        Apr 28, 2019#3

        It is also possible to copy and paste following code into a new file same with file extension .js as UltraEdit script file, add this script file to Script List and execute the script on active file from Script List to find lines matching the expression or simple string entered after script start and cut + paste them into a new file.

        Code: Select all

        if (UltraEdit.document.length > 0)  // Is any file opened?
        {
           // Define environment for this script.
           UltraEdit.insertMode();
           if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
           else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
        
           // Prompt user for the Perl regular expression string
           // to find string in a line to cut to a new file.
           var sSearch = UltraEdit.getString("Enter Perl regex string to find in lines to cut:",1);
           if (sSearch.length)
           {
              if (sSearch.charAt(0) != "^")
              {
                 sSearch = "^.*" + sSearch;
              }
              // Remove CR+LF, or only LF, or only CR or $ from end of search string.
              sSearch = sSearch.replace(/(?:\r?\n|\r|\$)$/,"");
        
              // Define the parameters for a Perl regular expression to find
              // entire lines matching case-insensitive the entered expression.
              UltraEdit.activeDocument.top();
              UltraEdit.perlReOn();
              UltraEdit.activeDocument.findReplace.mode=0;
              UltraEdit.activeDocument.findReplace.matchCase=false;
              UltraEdit.activeDocument.findReplace.matchWord=false;
              UltraEdit.activeDocument.findReplace.regExp=true;
              UltraEdit.activeDocument.findReplace.searchDown=true;
              if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
              {
                 UltraEdit.activeDocument.findReplace.searchInColumn=false;
              }
        
              // Run one search to check if the search expression finds
              // anything at all and if it matches also a line termination.
              if (UltraEdit.activeDocument.findReplace.find(sSearch))
              {
                 var nLastCharPos = UltraEdit.activeDocument.selection.length - 1;
                 var sLastChar = UltraEdit.activeDocument.selection.charAt(nLastCharPos);
                 if ((sLastChar != "\n") && (sLastChar != "\r"))
                 {
                    if (UltraEdit.activeDocument.lineTerminator < 1) sSearch += ".*(?:\\r\\n)?";
                    else if (UltraEdit.activeDocument.lineTerminator == 1) sSearch += ".*\\n?";
                    else if (UltraEdit.activeDocument.lineTerminator > 1) sSearch += ".*\\r?";
                 }
        
                 // Move caret to top of the active file and select + clear user clipboard 9.
                 UltraEdit.activeDocument.top();
                 UltraEdit.selectClipboard(9);
                 UltraEdit.clearClipboard();
        
                 // Run in a loop a Perl regular expression to find lines matching
                 // case-insensitive the expression and cut the lines to clipboard 9.
                 while (UltraEdit.activeDocument.findReplace.find(sSearch))
                 {
                    UltraEdit.activeDocument.cutAppend();
                 }
        
                 // Create a new file if lines were cut and paste the lines.
                 UltraEdit.newFile();
                 UltraEdit.activeDocument.paste();
                 // Make sure the last line has also a line termination.
                 if (UltraEdit.activeDocument.isColNumGt(1))
                 {
                    UltraEdit.activeDocument.insertLine();
                    if (UltraEdit.activeDocument.isColNumGt(1))
                    {
                       UltraEdit.activeDocument.deleteToStartOfLine();
                    }
                 }
                 UltraEdit.activeDocument.top();
                 UltraEdit.clearClipboard();
                 UltraEdit.selectClipboard(0);
              }
              else
              {
                 UltraEdit.messageBox("Nothing found matching the Perl regular expression: " + sSearch);
              }
           }
        }
        
        Depending on entered Perl regular expression the script can even find blocks and cut and paste them into a new file.

        Note: This quickly written script does not handle correct all entered regular expression search strings. For example on entering a regular expression with (?s) at beginning the search string is nevertheless modified to start with ^.* which is not correct in this case. See "." (dot) in Perl regular expressions doesn't include newline characters CRLF? for meaning of (?s) at beginning of a Perl regular expression string.
        Best regards from an UC/UE/UES for Windows user from Austria