Community
    • Login

    How do I delete a line with a certain number in it

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    10 Posts 4 Posters 650 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.
    • SquirtleshellS
      Squirtleshell
      last edited by

      How would I delete a line with a certain number in it?

      For example, If i had a big list of gift cards and i only wanted to keep the $100 ones, how would i delete everything else

      404009 = $20.0
      250863 = $100.0
      512852 = $20.0
      231558 = $10.0
      715462 = $100.0
      136968 = $20.0
      562535 = $100.0

      How would i delete everything except for the gift cards with the $100 balance

      astrosofistaA 1 Reply Last reply Reply Quote 0
      • astrosofistaA
        astrosofista @Squirtleshell
        last edited by

        Hi @Squirtleshell

        Try this:

        Open the Replace dialog (Ctrl + H) and type in:

        Search: (?-s)(^.*= \$100\.0\R)|.*\R
        Replace: $1
        

        Check the Wrap around option
        Select the Regular expression search mode
        Click on the Replace All button

        Hope this helps.

        SquirtleshellS 1 Reply Last reply Reply Quote 3
        • SquirtleshellS
          Squirtleshell
          last edited by Squirtleshell

          @astrosofista said in How do I delete a line with a certain number in it:

          Search: (?-s)(^.= $100.0\R)|.\R
          Replace: $1

          I tried it, but it just deleted everything.

          Edit: nvm it worked

          1 Reply Last reply Reply Quote 0
          • SquirtleshellS
            Squirtleshell @astrosofista
            last edited by

            @astrosofista After removing the ones with the $100 balance, it becomes

            250863 = $100.0
            715462 = $100.0
            562535 = $100.0

            How would I remove the “= $100.0” and only keep the numbers?

            astrosofistaA 2 Replies Last reply Reply Quote 0
            • astrosofistaA
              astrosofista @Squirtleshell
              last edited by

              @Squirtleshell

              Then try a normal search mode:

              Search: = $100.0
              Replace: [leave empty]

              Beware that there is a space at the left of the equal sign, so the complete search expression is " = $100.0".

              1 Reply Last reply Reply Quote 1
              • astrosofistaA
                astrosofista @Squirtleshell
                last edited by

                Hi @Squirtleshell

                Taking a second look at this, if you were only interested on that numbers alone, you can run search on the first list you provided in order to get the desired outcome in only one search, as follows:

                Search: (?-s)^\d+\K = \$100\.0|.+\R
                Replace: [leave empty]

                As before, check the Wrap around option
                Select the Regular expression search mode
                Click on the Replace All button

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

                  Hello, @squirtleshell, @astrosofista and all,

                  Here is my version :

                  SEARCH (?-s)^(\d+) = (\$100)?.+(\R)

                  REPLACE ?2\1\3


                  Notes :

                  • If group 2 exists ( lines with $100) , we rewrite the digits ( \1 ) and the EOL chars ( \3 )

                  • If group 2 not defined, as optional ( the ? quantifier means {0,1} ), the entire line with its line-break is not taken in account !

                  Best Regards,

                  guy038

                  1 Reply Last reply Reply Quote 2
                  • SquirtleshellS
                    Squirtleshell @astrosofista
                    last edited by

                    @astrosofista

                    Could you help me out with this one:

                    309998 = $100.0
                    839998 = $100.0
                    526909 = $100.0
                    485971 = $15.0
                    078137 = $20.0
                    331982 = $10.0
                    774329 = 100.0%
                    249357 = $15.0
                    658676 = $10.0
                    081804 = $15.0
                    049664 = 100.0%
                    919693 = 100.0%

                    How would I keep the $100.0 and 100.0% and remove everything else.
                    And after i remove the smaller amounts, how would I remove the “= $100.0 or 100.0%?”

                    astrosofistaA 1 Reply Last reply Reply Quote 0
                    • astrosofistaA
                      astrosofista @Squirtleshell
                      last edited by

                      @Squirtleshell said in How do I delete a line with a certain number in it:

                      Could you help me out with this one:
                      […]
                      How would I keep the $100.0 and 100.0% and remove everything else.

                      Sure. As we did before, open the Replace dialog (Ctrl + H) and type in:

                      Search: (?-s)(^.*= \$?100\.0%?\R)|.*\R
                      Replace: $1
                      

                      Check the Wrap around option
                      Select the Regular expression search mode
                      Click on the Replace All button

                      And after i remove the smaller amounts, how would I remove the “= $100.0 or 100.0%?”

                      Under the same conditions as above, try the following regex:

                      Search: (?-s)^\d*\K = \$?100\.0%?
                      Replace: [leave empty]
                      

                      Hope this helps.

                      1 Reply Last reply Reply Quote 3
                      • Terry RT
                        Terry R
                        last edited by

                        @Squirtleshell said in How do I delete a line with a certain number in it:

                        How would I keep the $100.0 and 100.0%

                        Assuming everything is on separate lines then you can use the bookmark feature. This is available under the main menu option “Search”, then look for “Mark”.
                        In the field just type 100\.0 (assuming search mode is regular expression, otherwise just 100.0 under “Normal” search mode as the . character has special meaning). So one mark operation with the “bookmark” option ticked will find both the $ and the % lines.
                        Once the lines have been marked you should see a character at the start of each line marked, usually a blue circle. Now you can remove the non marked lines by using “Search”, “Bookmark” and then “Remove Unmarked Lines”.
                        That completes the solution to your first problem.

                        As the the second question, how to keep only the code at the start of each remaining line, this I’d do with a regular expression.
                        So using the Replace function (as has been shown before) we have
                        Find What:(?-s)^(\d+).+
                        Replace With:\1
                        Make sure “regular expression” selected for search mode, wrap around should be ticked. Click on the “Replace All” button.

                        Terry

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