Hide lines NOT matching search string

Hide lines NOT matching search string

26
Basic UserBasic User
26

    Mar 11, 2008#1

    Using: UEStudio 6.50+4

    Would someone please post and/or send me a simple sample script and/or macro to hide all lines NOT matching a search string in file that is opened in one of the tabs(i.e UEStudio window).

    tia

    6,677581
    Grand MasterGrand Master
    6,677581

      Mar 11, 2008#2

      Hiding single lines is not possible at the moment. Only a block can be made hidden. And as several times written a search for a line not containing a string is not possible (maybe with Perl, I'm not a Perl expert). You can run a regular expression replace for lines containing a string, which adds a special character at start of the lines containing the string, then run a replace which deletes all lines not starting with the special character and last run a third regular expression to delete the special character at start of the remaining lines. Or you search for lines with a specific string and use the find option List Lines Containing String which you then can copy to a new file.

      Edited on 2010-03-02: See also my post Filtering lines using the Find command with UE v16.00+.
      Best regards from an UC/UE/UES for Windows user from Austria

      236
      MasterMaster
      236

        Mar 11, 2008#3

        Well, a Perl regex that matches a consecutive block of lines that don't contain a certain string is

        Code: Select all

        (?:^(?:(?!%REGEX%).)*$\r\n)+
        where %REGEX% has to be substituted by the search string that you need (careful: special characters like [\^$.|?*+(){} have to be escaped by a backslash, i.e. \* will match a *).

        However, I'm running into a problem when trying to hide a block like this as the option to hide selected lines is grayed out in my UE V14.00+4 (even if there are multiple lines selected), and I don't know why. Maybe Mofi can help here.

        The problem remains, though, that single lines (that will also be matched by this regex) cannot be hidden. So maybe using a search for

        Code: Select all

        ^(?:(?!%REGEX%).)*$\r\n
        and choosing the option "List lines containing string" will approach better what you need.

        HTH,
        Tim

        6,677581
        Grand MasterGrand Master
        6,677581

          Mar 11, 2008#4

          Tim, you have to enable at Configuration - Editor Display - Code Folding the 2 settings:

          Enable show/hide lines and code folding
          Enable show/hide lines in non syntax highlighted files
          Best regards from an UC/UE/UES for Windows user from Austria

          236
          MasterMaster
          236

            Mar 11, 2008#5

            Thanks, Mofi!

            I've just tried it, and it works "as designed", i.e., it won't be (I guess) what spaceBAR wanted because the first line of a hidden block remains visible (and therefore a single line can't be hidden, either). So it comes back to the "List lines containing string" method mentioned earlier...

            344
            MasterMaster
            344

              Mar 11, 2008#6

              You won't get lucky trying to find a solution with any regexp-approach NOT finding sth.
              So you might write a small macro that goes through the code line by line,
              examine that line and if "string not found" then append to "clipboard 9".
              So you can collect all lines without the string and paste them to a new document.
              Disadvantage: Potentially slow, only a copy of the document is created (not a filter or sth.)
              Normally using all newest english version incl. each hotfix. Win 10 64 bit

              236
              MasterMaster
              236

                Mar 11, 2008#7

                Hi Bego,

                what's wrong with "List lines containing string" using ^(?:(?!%REGEX%).)*$\r\n as the search string? I'm probably overlooking something...

                Cheers,
                Tim

                344
                MasterMaster
                344

                  Mar 11, 2008#8

                  Hi Tim,

                  maybe I am missing sth.
                  If I have a file like this:

                  Code: Select all

                  bblabla
                  mmgla
                  lalala
                  blubb
                  blubb lala blubb
                  kjf
                  another lala blub
                  end
                  and I do a regexp-search with

                  Code: Select all

                  ^(?:(?!%lala%).)*$\r\n
                  and "list lines containing" checked, i get all lines displayed.

                  UE 14.00+3
                  Normally using all newest english version incl. each hotfix. Win 10 64 bit

                  236
                  MasterMaster
                  236

                    Mar 11, 2008#9

                    Hi Bego,

                    remove the % signs - you want to search for ^(?:(?!lala).)*$\r\n instead.

                    :)

                    Tim

                    P.S.: The last line has to be \r\n terminated, too, or it won't match...

                    344
                    MasterMaster
                    344

                      Mar 11, 2008#10

                      Aaaah, bingo. OK, that is really a good thing now, thx Tim :-)
                      So, even myself can learn a bit from time to time ;-)

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

                      3
                      NewbieNewbie
                      3

                        Apr 15, 2008#11

                        The approach I took on this was to use grep.

                        I have cygwin installed on my machine and simply created a tool
                        Inverse Grep

                        C:\cygwin\bin\grep.exe -v %sel% %F


                        I also have one without -v simply called grep.

                        I like this because it spits it out into a new window for easy further editing.

                        344
                        MasterMaster
                        344

                          Apr 15, 2008#12

                          Hi boefei,

                          I tried it out because I did not know Cygwin yet and also miss grep on Windows systems. Runs smart. Thank you for the tip.

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

                          3
                          NewbieNewbie
                          3

                            Apr 15, 2008#13

                            No problem

                            Forgot to add just highlight the item you want(want removed) and run the command.


                            MFG
                            Wer nicht fragt, bleibt dumm.

                            3
                            NewbieNewbie
                            3

                              Apr 24, 2008#14

                              I am wanting something like what spacebar is asking for except I don't want to create a new file with the lines matching the search. I want to collapse all lines NOT matching the search so I can easily edit the ones matching the criteria and then re-expand the whole file with my changes in place.

                              What about something like that?

                              344
                              MasterMaster
                              344

                                Apr 24, 2008#15

                                There is just the find-option "list lines containing string" that opens a new window with all those lines.
                                You then can double-click those lines one by one and edit them.
                                But the feature you describe is not implemented (yet)
                                Normally using all newest english version incl. each hotfix. Win 10 64 bit

                                Read more posts (14 remaining)