Community
    • Login

    How to bookmark lines around a line containing a specific expression 'XXX' ?

    Scheduled Pinned Locked Moved General Discussion
    31 Posts 6 Posters 6.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sam rathodS
      sam rathod @guy038
      last edited by PeterJones

      @guy038
      Hey, i am trying to extract 10 lines above word “ignored”, i tried using this command from your other post (.*\R){10}^.*ignored.*\R but it is showing Invalid Regular Expression.
      Following are few lines from the whole text file.l, can u help me out. Thanks for your valuable posts.

            B465  B416  100.00    0.00    0.00     1.17   -32.75   -12.11   346.17   791.11  1618.77    0.042
      B483  B478  B486  100.00    0.00    0.00    -0.88    -2.81     1.55   211.14   417.77   795.80    0.007
            B478  B363  100.00    0.00    0.00     4.29    -2.66   -14.84   302.41   721.07  1413.40    0.011
      B479  B476  B477    0.00  100.00    0.00    -0.35     2.33     0.63   183.52   417.34   794.06    0.006
            B476  B481   26.71   73.29    0.00    -0.61    -4.35    -2.34   190.81   417.34   794.06    0.011
            B476  B361  100.00    0.00    0.00     3.32    -1.65    32.38   217.19   472.63   999.46    0.033
      B477  B479  B473    3.69   96.31    0.00    -5.24    -5.33     0.82   258.08   587.08  1162.04    0.010
            B479  B485    0.00  100.00    0.00    -5.05     4.64     2.77   256.20   587.08  1162.04    0.009
            B479  B408  100.00    0.00    0.00    -2.39   -10.75   -12.76   421.63   791.10  1618.76    0.016
      B489  B479  B487   41.71   58.29    0.00    -0.69    -2.92     0.72   195.22   417.80   795.95    0.007
            B479  B485    0.00  100.00    0.00    -0.39     0.16     0.72   183.81   417.80   795.95    0.001
            B479  B363  100.00    0.00    0.00     0.26    -1.57    22.99   217.53   473.15  1001.83    0.023
      B485  B489  B477    9.91   90.09    0.00    -5.01    -5.55     0.06   261.25   587.09  1162.07    0.010
            B489  B492    0.00  100.00    0.00    -4.52    -4.82     4.16   256.20   587.09  1162.07    0.009
            B489  B417  100.00    0.00    0.00     0.30    -6.94    -7.89   346.17   791.11  1618.80    0.010
       
      [FF]
      
      SACS CONNECT Edition V(15.1) - CL                                                        Company: Lamprell Energy Ltd.
             CRPO-126-MRJN 2050/2059 - JACKET BOAT IMPACT ANALYSIS                        DATE 11-MAR-2024  TIME 06:50:22   CLP PAGE 1151
      
                                            ** SACS COLLAPSE IMPACT ENERGY ABSORPTION **
       
       
                                              INCREMENT  37          LOAD FACTOR     6.200
       
                                                      Aggregate          Incremental
                                                         (MJ)                (MJ) 
                    Energy absorbed by structure  =        0.1262              0.0021
                    % of total energy absorbed    =      100.9477   (%)        1.6442   (%)
       
       
           **** WARNING - IMPACT ENERGY ABSORBED AT LOAD STEP    37
           **** WARNING - THE REMAINING    96 INCREMENT(S) OF THE LOAD STEP WILL BE IGNORED
       
      [FF]
      SACS CONNECT Edition V(15.1) - CL                                                        Company: Lamprell Energy Ltd.
      
             CRPO-126-MRJN 2050/2059 - JACKET BOAT IMPACT ANALYSIS                        DATE 11-MAR-2024  TIME 06:50:22   CLP PAGE 1152
      
                **** FINAL DEFLECTIONS AND ROTATIONS FOR LOAD SEQUENCE LCE1 ****
                                       LOAD CASE OE01
                                     LOAD FACTOR  6.200
       
       
                         ****** DEFLECTIONS ******   ******* ROTATIONS *******
                JOINT       X        Y        Z          X        Y        Z
                            CM       CM       CM        RAD      RAD      RAD
       
       
                0243       0.192   -0.712   -0.005    0.00146  0.00058 -0.00019
                0269       0.348   -0.873   -0.736    0.00168  0.00070  0.00022
                0276       0.399   -0.518   -1.297    0.00117  0.00063  0.00030
                0277       0.137   -0.584   -0.590    0.00151  0.00037  0.00020
                101L       0.364   -0.914   -0.734    0.00168  0.00070  0.00022
                102L       0.414   -0.547   -1.296    0.00117  0.00063  0.00030
      

      Regards,
      Aaditya

      —

      moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

      PeterJonesP mkupperM 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @sam rathod
        last edited by

        @sam-rathod said in How to bookmark lines around a line containing a specific expression 'XXX' ?:

        post (.*\R){10}^.*ignored.*\R but it is showing Invalid Regular Expression.

        What you typed in your post is valid regex, so I have to assume that’s not what you had in the FIND WHAT field. If that’s exactly what you had, please show a screenshot of the whole dialog box

        sam rathodS 1 Reply Last reply Reply Quote 0
        • mkupperM
          mkupper @sam rathod
          last edited by mkupper

          @sam-rathod As @PeterJones noted, your regular expression is valid.

          @all - I discovered it’s challenging as I think I think @sam-rathod intended to start the extraction at the line that starts with SACS CONNECT Edition and that the does not count empty or blank-only lines as “lines.”

          But, how can can we go backwards by nine lines that are not blank/empty from the IGNORED anchor?

          Thinking forwards is much easier for me: ^SACS CONNECT Edition(?s).*IGNORED(?-s).*

          @sam-rathod the (?s) part puts the regular expression engine in a mode where dot also matched end of lines meaning we will skip/match all lines from SACS CONNECT Edition up to the word IGNORED. Once we get to IGNORED we do (?-s) which turns the dot matching end-of-line thing off and the final .* picks up the remainder of the line.

          To make this safer I would use the case-sensitive (?-i)^SACS CONNECT Edition(?s).*IGNORED(?-s).*

          sam rathodS 1 Reply Last reply Reply Quote 2
          • sam rathodS
            sam rathod @PeterJones
            last edited by

            @PeterJones
            Hey
            The output that I am expecting:
            e256c5ec-61e7-4f9b-b662-7a0ff7ac65cd-image.png
            The area marked in grey is what i want MARKED

            This is the error that it is showing after entering the regex command:
            6245c6bf-ff6b-4d21-a8d7-bad8664c1be3-image.png

            I tried attaching files but i am unable to.

            Thanks guys for reaching out so quick to such an old topic, much appreciated.

            Regards,
            Aaditya

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • sam rathodS
              sam rathod @mkupper
              last edited by

              @mkupper
              Hello,

              Actually the occurrence of SACS CONNECT Edition is at multiple times so i guess that might be one issue, also i tried the <(?-i)^SACS CONNECT Edition(?s).IGNORED(?-s).> but it is giving this error:
              ca22ddb2-1218-4703-8eb2-f88b6b6a7dbf-image.png

              Regards,
              Aaditya

              mkupperM 1 Reply Last reply Reply Quote 0
              • mkupperM
                mkupper @sam rathod
                last edited by

                @sam-rathod - I start out by trying to see if there is a pattern to the data that I can take advantage of. I test this carefully to understand any possible exceptions to the pattern.

                You have provided two examples and so from that the pattern I see is the the sections that you want to highlight start with these lines:

                                                      ** SACS COLLAPSE IMPACT ENERGY ABSORPTION **
                          **** FINAL DEFLECTIONS AND ROTATIONS FOR LOAD SEQUENCE LCE1 ****
                

                I also see that above this is the page header which starts with SACS CONNECT Edition and so first do a test (?-i)^SACS CONNECT Edition and count how many page headers there are. Let’s say there are 957 in the file. I write down 957 so I won’t forget.

                I then build a regular expression that matches the start of the data. I’ll do (?-i)^ +\*+ [A-Z0-9 ]+ \*+$ and verify that it matches exactly 957 times in the file. If it fails to match exactly 957 times then I tighten or loosen the regular expression as needed until it nails 957.

                I do the same thing for the IGNORED lines. I first do (?-i)IGNORED$ and count. Let’s say there are 57 and so I write that down. The full pattern for the IGNORED lines seems to be (?-i)^ +\*{4} WARNING - THE REMAINING +[0-9]+ INCREMENT\(S\) OF THE LOAD STEP WILL BE IGNORED$ Adjust that expression until it gets exactly 57 matches.

                Now we know we have 957 page headers and 57 of them are the ones we are interested in. As the sample size you have provided only has one example of what we want to match I will use a more general

                (?-i)^(?: +\*+ [A-Z][A-Z0-9 ]+ \*+\R)(?:.*\R){1,25}(?: +\*{4} WARNING - THE REMAINING +[0-9]+ INCREMENT\(S\) OF THE LOAD STEP WILL BE IGNORED)$
                

                Drop that into Notepad++. I added a couple of extra parentheses in there so that when you move the cursor to a ( or ) that Notepad++ will highlight the other one of of the ( … ) pairs.

                The groups within that rather long expression are:

                • (?-i) - Turn the ignore letter case flag off.
                • ^(?: +\*+ [A-Z][A-Z0-9 ]+ \*+\R) - This is the thing that matches the start of the blocks we want to select. We know it matches 957 times.
                • (?:.*\R){1,25} - Allow for one to 25 lines that may be empty or may have stuff.
                • (?: +\*{4} WARNING - THE REMAINING +[0-9]+ INCREMENT\(S\) OF THE LOAD STEP WILL BE IGNORED)$ - This matches the last line of the things we are interested in.

                In this case I solved the problem by using (?:.*\R){1,25}. I know that the first line will match many times but don’t want to bother with scanning too far before testing for the last line. With a better sample size I likely would tune {1,25} to be a better match for how far down that IGNORED line is.

                sam rathodS 1 Reply Last reply Reply Quote 1
                • PeterJonesP
                  PeterJones @sam rathod
                  last edited by PeterJones

                  @sam-rathod said in How to bookmark lines around a line containing a specific expression 'XXX' ?:

                  This is the error that it is showing after entering the regex command:

                  That’s an exeedingly fuzzy screenshot.
                  3492b2f6-8569-4ac7-a3a9-cff5dfa764b0-image.png
                  But to me, that looks a lot more like (.*\R}{10}^.*ignored.*\R instead of (.*\R){10}^.*ignored.*\R – the first group is accidentally closed by a curly-brace } instead of a close-parenthesis ). Assuming that fuzzy character really is }, I can replicate your error; and if I hover over the ... in the error message, it tells me exactly what’s gone wrong with the expression:
                  faf7ceca-84f5-4d1c-b78f-463aa4d851a0-image.png

                  If it’s actually something else wrong with yours, that ... hover will help you diagnose it.

                  But either way, if I enter the regex that you claimed to use, rather than the one that your fuzzy screenshot shows, it just shows that it’s not finding text, not that there was an error in the regex.

                  2f4372d8-d9ec-485a-86d0-6d75d991254e-image.png

                  I tried attaching files but i am unable to.

                  That’s not the right way of sharing data, as has been explained in the FAQs about formatting example text and the template for search/replace questions. Those FAQs show how to format your text so that it appears in the copyable text box (which is how I changed your original post using moderator powers to show the data in the text box – I will actually go back and remove the extra line endings, which may have been accidentally introduced when I did the first edit).

                  When i use the expression that you said you were using, on the data that you had in your post, I match almost what your followon post said you wanted to match:

                  606b245c-6f7e-4620-b960-481276681591-image.png

                  The reason it doesn’t match everything is because you said you wanted 10 lines before the “ignored” line… but your screenshot with manual highlight shows that you actually wanted 12 lines before the “ignored” line, so you just need to change the count from {10} to {12} …

                  And, as your regex uses ignored but your actual text is IGNORED, and as we want to make sure that the . from the first capture group doesn’t match newlines, the final regex you should use is
                  FIND WHAT = (?i-s)(.*\R){12}^.*ignored.*\R – as shown below, this matches what you say you want to match.

                  4383f782-17e9-4e4b-8544-b9257dca3ada-image.png

                  sam rathodS 1 Reply Last reply Reply Quote 1
                  • sam rathodS
                    sam rathod @mkupper
                    last edited by

                    @mkupper said in How to bookmark lines around a line containing a specific expression 'XXX' ?:

                    (?-i)^(?: +*+ [A-Z][A-Z0-9 ]+ *+\R)(?:.*\R){1,25}(?: +*{4} WARNING - THE REMAINING +[0-9]+ INCREMENT(S) OF THE LOAD STEP WILL BE IGNORED)$

                    This did the wonder, thanks for the help man on my own i would never been able to figure this out. I am new to notepad++ will appreciate if you can share some learning material to start from basics.

                    Thanks a Lot.

                    Regards,
                    Aaditya

                    1 Reply Last reply Reply Quote 0
                    • sam rathodS
                      sam rathod @PeterJones
                      last edited by

                      @PeterJones said in How to bookmark lines around a line containing a specific expression 'XXX' ?:

                      (?i-s)(.*\R){12}^.ignored.\R

                      The screenshot looks fuzzy but i had entered the same equation that was been mentioned by @guy038.

                      Will go through the FAQs for sharing data and will understand how to post on this.

                      I tried the final Regex :

                      (?i-s)(.*\R){12}^.*ignored.*\R
                      

                      27da62cf-3dc0-462b-aa57-00c5e2c74694-image.png

                      Thanks for actively resolving the issue i was facing, will appreciate if u can share some learning material to start from the basics.

                      Thanks & Regards,
                      Aaditya

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @sam rathod
                        last edited by

                        @sam-rathod said in How to bookmark lines around a line containing a specific expression 'XXX' ?:

                        will appreciate if u can share some learning material to start from the basics

                        A good starting point is HERE.

                        1 Reply Last reply Reply Quote 2
                        • guy038G
                          guy038
                          last edited by guy038

                          Hello, @sam-rathod, @peterjones, @mkupper, @alan-kilborn and All,

                          I suppose that dealing with files with important size may lead to this regex message, even if this regex does work properly with small files :-((

                          So, @sam-rathod, could you try with this new regex version :

                          SEARCH/MARK (?-is)^(?:.*\R){12}.*IGNORED.*\R

                          Best Regards,

                          guy038

                          1 Reply Last reply Reply Quote 1
                          • sam rathodS
                            sam rathod
                            last edited by sam rathod

                            Hello,

                            If i have range of text for example

                            "This is the specific text in the document that i will search"
                            Line1 that dont want marked
                            Line2 that dont want marked
                            
                            Line3 that dont want marked
                            
                            Line 1 want to mark
                            Line 2 want to mark
                            Line 3 want to mark
                            Line 4 want to mark
                            Line 5 want to mark
                            
                            ""This is the specific text in the document that i will search"
                            Line1 that dont want marked
                            Line2 that dont want marked
                            
                            Line3 that dont want marked
                            
                            Line 6 want to mark
                            Line 7 want to mark
                            Line 8 want to mark
                            Line 9 want to mark
                            Line 10 want to mark
                            

                            The output i am expecting

                            Line 1 want to mark
                            Line 2 want to mark
                            Line 3 want to mark
                            Line 4 want to mark
                            Line 5 want to mark
                            Line 6 want to mark
                            Line 7 want to mark
                            Line 8 want to mark
                            Line 9 want to mark
                            Line 10 want to mark
                            
                            ^.*This is the specific text in the document that i will search.*\R(?:.*\R){5}((?:.*\R){5})
                            

                            Tried various option but unable to skip the lines as everything after specific text is getting marked.

                            Regards,
                            Aa

                            1 Reply Last reply Reply Quote 0
                            • guy038G
                              guy038
                              last edited by

                              Hi, @sam-rathod and All,

                              I do not understand clearly what you want to achiveve !

                              Given this INPUT text, below :

                              "This is the specific text in the document that i will search"
                              Line1 that dont want marked
                              Line2 that dont want marked
                              
                              Line3 that dont want marked
                              
                              Line 1 want to mark
                              Line 2 want to mark
                              Line 3 want to mark
                              Line 4 want to mark
                              Line 5 want to mark
                              
                              ""This is the specific text in the document that i will search"
                              Line1 that dont want marked
                              Line2 that dont want marked
                              
                              Line3 that dont want marked
                              
                              Line 6 want to mark
                              Line 7 want to mark
                              Line 8 want to mark
                              Line 9 want to mark
                              Line 10 want to mark
                              

                              And let’s suppose that you’ve previously bookmarked all the lines with the Line #..# want to mark syntax

                              Then just use the Search > Bookmark > Remove Unmarked lines option and you’re left with the following expected OUTPUT text :

                              Line 1 want to mark
                              Line 2 want to mark
                              Line 3 want to mark
                              Line 4 want to mark
                              Line 5 want to mark
                              Line 6 want to mark
                              Line 7 want to mark
                              Line 8 want to mark
                              Line 9 want to mark
                              Line 10 want to mark
                              

                              Best Regards,

                              guy038

                              ~

                              sam rathodS 1 Reply Last reply Reply Quote 0
                              • sam rathodS
                                sam rathod @guy038
                                last edited by

                                @guy038
                                No i am not able to bookmark only the specific line that i want mark.

                                Basically i want to find a specific text , ignore 4 lines after it and mark& select 5 line after the specific text & 4 lines.

                                sam rathodS 1 Reply Last reply Reply Quote 0
                                • sam rathodS
                                  sam rathod @sam rathod
                                  last edited by

                                  @sam-rathod

                                  Sample of data i am trying to figure out.

                                  tmp_f01d3921-e931-4f57-b01c-3308f3437ea2.png

                                  1 Reply Last reply Reply Quote 0
                                  • guy038G
                                    guy038
                                    last edited by guy038

                                    Hello, @sam-rathod and All,

                                    Ah, OK. Now, I understand all the story !

                                    Just note that you should have put your text as raw text, using the </> indication when replying and not pasting an image. Indeed, even with a OCR plugin, within my favorite graphic viewer, I was not able to convert the letters of your image into raw text :-(( This explains the delay of my reply !


                                    So, with this kind of INPUT text :

                                    
                                     SACS CONNECT Edition V(15.1) - CL                                                        Company: .
                                                 *********** SACS IX SEASTATE PROGRAM ***********               DATE 23-OCT-2024  TIME 07:31:44   SEA PAGE   208
                                                                         ***** SEASTATE COMBINED LOAD CASE SUMMARY *****
                                                                                  RELATIVE TO MUDLINE ELEVATION
                                       LOAD  LOAD              FX           FY           FZ           MX           MY           MZ
                                       CASE  LABEL
                                                              (KN)         (KN)         (KN)       (KN-M)       (KN-M)       (KN-M)
                                                             
                                       127  7119             -125.62      -190.83     -4342.63       4582.3      -3032.8      -1382.1
                                       128  7120                0.54      -212.18     -4388.18       5164.0        863.9      -1432.1
                                       129  7121              111.01      -159.93     -4333.70       3602.5       4267.7      -1399.5
                                       130  7122              202.80       -78.61     -4340.74       1053.9       7076.4      -1374.5
                                       131  7131              264.55       -39.54     -4341.04       1111.7       8733.7      -1299.3
                                    

                                    Just use the search regex, below, in order to mark the expected lines :

                                    SEARCH / MARK (?-is)^.+SEASTATE COMBINED LOAD CASE SUMMARY.+\R(?:.+\R){5}\K(?:.+\R){5}


                                    Notes :

                                    • Note that I use non-capturing groups (?:.......), instead of capturings ones (.......), for each block of five lines.

                                    • Now, after the complete line containing the string SEASTATE COMBINED LOAD CASE SUMMARY, with this exact case

                                    • And the five lines that follow,

                                    • The \K syntax cancel any previous search, so far

                                    • So, the next five lines are only taken in account by the regex engine and marked


                                    Method :

                                    • Open the Mark dialog ( Ctrl + M )

                                    • Uncheck all box options

                                    • SEARCH / MARK (?-is)^.+SEASTATE COMBINED LOAD CASE SUMMARY.+\R(?:.+\R){5}\K(?:.+\R){5}

                                    • Just check the Bookmark line, Purge for each search and Wrap around box options

                                    • Select the Regular expression search mode

                                    • Click on the Mark All button

                                    • Now, you may either :

                                      • Copy all these bookmarked lines in an other new tab with the Search > Bookmark > Copy Bookmarked Lines option

                                      • Click on the Copy Marked Text button and paste the clipboard contents in an other tab

                                    Best Regards

                                    guy038

                                    sam rathodS 1 Reply Last reply Reply Quote 0
                                    • sam rathodS
                                      sam rathod @guy038
                                      last edited by

                                      @guy038
                                      Sorry for the inconvenience caused.

                                      Thanks a lot will try this. I m sure this will work.

                                      Regards,
                                      Aa

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post
                                      The Community of users of the Notepad++ text editor.
                                      Powered by NodeBB | Contributors