Bookmark lines then copy to clipboard?

Bookmark lines then copy to clipboard?

4
NewbieNewbie
4

    Sep 24, 2006#1

    I used to use Textpad as my preferred text editor but switched to UltraEdit primarily because fo its excellent macro engine. That said, Textpad had a very good feature which I don't see in UE. When searching text, it was possible to bookmark all matching lines, and when copying txt, it was possible to copy bookmarked lines.

    Perhaps this is possible to do by macro (but a quick search on this forum didn't find any such macro, whihc suggests may be it's *not* possible), but there is also the issue of limited bookmarks (I sometimes work on files many thousands of lines long, and I know there is (used to be?) a limit on bookmarks).

    Thanks in advance.

    6,675585
    Grand MasterGrand Master
    6,675585

      Sep 24, 2006#2

      Do you want to copy all bookmarked lines to clipboard?
      Yes, see Copy to clipboard bookmarked lines?

      Or do you want to run a search and copy all lines where search string is found to clipboard?
      Yes, than enable in the Find dialog the option List Lines Containing String, run the search and finally press the Clipboard button in the dialog which shows all lines with the search string.
      Best regards from an UC/UE/UES for Windows user from Austria

      4
      NewbieNewbie
      4

        Sep 24, 2006#3

        Hi Mofi,
        Thanks for the quick response. I think I wasn't too clear - I want to run a search (perhaps several times, with different strings) and bookmark lines which match the given search term(s). Having done that, *then* I can use the macro that you've pointed me at.

        I know I *could* use a regular expression to search for "A" OR "B" OR "C", but I would rather search for each in turn (so I can just highlight the search term and hit Alt+F3.

        6,675585
        Grand MasterGrand Master
        6,675585

          Sep 25, 2006#4

          You know that bookmarks are limited to 50?

          Use the following macro with or without command Top with or without Find option MatchCase to bookmark all lines with the currently selected string. The macro property Continue if a Find with Replace not found must be checked for this macro.

          IfSel
          Clipboard 9
          Copy
          Top
          Loop
          Find MatchCase "^c"
          IfFound
          ToggleBookmark
          Else
          ExitLoop
          EndIf
          EndLoop
          ClearClipboard
          Clipboard 0
          EndIf


          Please note: ToogleBookmark clears also a bookmark. So if a string is found in a line where a bookmark is already set, the bookmark will be deleted instead of set.

          To solve this problem it would be necessary for example to insert a special character at start of a bookmarked line which could be checked with IfCharIs before ToggleBookmark is used. But then you have to delete this special marker character at every line before copying the bookmarked lines to the clipboard.

          Well, with this special marker character bookmarking the lines is not really needed anymore. The special marker character marks the lines which then should be copied with a second macro to the clipboard which also removes the marker character.
          Best regards from an UC/UE/UES for Windows user from Austria

          1
          NewbieNewbie
          1

            Oct 25, 2006#5

            I also am a long-time TextPad user and was looking to see if UltraEdit could replace it. The Copy Bookmarked Lines feature is also something that I use in TextPad, and I was looking to see if UltraEdit could do it.

            I'm sad to see that it currently does not, because I frequently use the feature when gleaning relevant info from log files. The procedure I can do in TextPad is ...

            1) Search for lines matching a certain pattern
            2) click Mark All
            3) repeat steps 1 & 2 until you've marked all the lines of various patterns you're interested in.
            4) Copy/Bookmarked Lines.
            5) Paste the lines into a new doc.

            I don't see any way of doing this in UltraEdit. UE's limitation of 50 bookmarks makes it impossible to use bookmarks, but perhaps you could have another concept, that of "marked" lines, which do less than your full bookmark feature, but would allow marking and copying.

            6,675585
            Grand MasterGrand Master
            6,675585

              Oct 25, 2006#6

              rhand you could use the Find option List Lines containing string. If you additionally use the Perl regex engine and use a Perl regex search string with all your patterns in an OR expression, you can find all lines at once and copy it then to clipboard. The OR argumentes for UltraEdit or legacy Unix engine are limited to 2 (only A OR B, but not A OR B OR C OR ...), that's why the Perl engine must be used.


              It's also possible to create a macro which in a loop asks you for the search string, marks the lines with the string and when you break the loop, copies all marked lines to windows clipboard and removes the marks.

              Here is an example for such a macro. It uses the UltraEdit style regex, because ^c can be used in a regex search&replace only with UltraEdit style.

              Please note: The search string you enter is interpreted as UltraEdit style regular expression search string and not a simple text.

              For details see my small tutorial for ^s and ^c. That's no problem when you search for strings which contains only of letters and numbers, but be careful with special characters which must be escaped with ^ when they should be found as characters and are UltraEdit style regular expression characters.

              You can extend the macro with additional questions for example with "Use match case? or "Use match word?". You can also use an other regular expression engine or do it without any regular expressions. But this would cause to use submacros because nested loops are not possible and you cannot use ^c in a regular expression replace all with an other regex engine, and so you have to mark the lines in an additional loop with non regex search + insert marker string.

              Last the file must be opened with write access because it must be temporarily modified. After macro execution the file is like it was before macro execution. (Except you have a line which starts with #|#, use a different marker string in this case.)

              InsertMode
              ColumnModeOff
              HexOff
              UnixReOff
              Top
              "
              "
              Loop
              Top
              GetString "Enter your search string, # breaks loop!"
              Key HOME
              IfColNumGt 1
              Key HOME
              EndIf
              IfCharIs "#"
              DeleteLine
              ExitLoop
              EndIf
              StartSelect
              Key END
              Cut
              EndSelect
              Find RegExp "%^(*^c^)"
              Replace All "#|#^1"
              EndLoop
              Loop
              Find RegExp "%#|##|#"
              Replace All "#|#"
              IfNotFound
              ExitLoop
              EndIf
              EndLoop
              ClearClipboard
              Loop
              Find RegExp "%#|#"
              IfNotFound
              ExitLoop
              Else
              Delete
              SelectLine
              CopyAppend
              EndSelect
              EndIf
              EndLoop
              Top

              Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
              Best regards from an UC/UE/UES for Windows user from Austria