• Login
Community
  • Login

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

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 4 Posters 724 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.
  • S
    Squirtleshell
    last edited by Jun 16, 2020, 2:47 AM

    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

    A 1 Reply Last reply Jun 16, 2020, 3:19 AM Reply Quote 0
    • A
      astrosofista @Squirtleshell
      last edited by Jun 16, 2020, 3:19 AM

      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.

      S 1 Reply Last reply Jun 16, 2020, 7:49 PM Reply Quote 3
      • S
        Squirtleshell
        last edited by Squirtleshell Jun 16, 2020, 7:33 PM Jun 16, 2020, 7:32 PM

        @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
        • S
          Squirtleshell @astrosofista
          last edited by Jun 16, 2020, 7:49 PM

          @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?

          A 2 Replies Last reply Jun 16, 2020, 8:39 PM Reply Quote 0
          • A
            astrosofista @Squirtleshell
            last edited by Jun 16, 2020, 8:39 PM

            @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
            • A
              astrosofista @Squirtleshell
              last edited by Jun 16, 2020, 9:10 PM

              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

              S 1 Reply Last reply Jun 23, 2020, 1:27 AM Reply Quote 2
              • G
                guy038
                last edited by guy038 Jun 16, 2020, 11:37 PM Jun 16, 2020, 11:29 PM

                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
                • S
                  Squirtleshell @astrosofista
                  last edited by Jun 23, 2020, 1:27 AM

                  @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%?”

                  A 1 Reply Last reply Jun 23, 2020, 3:30 AM Reply Quote 0
                  • A
                    astrosofista @Squirtleshell
                    last edited by Jun 23, 2020, 3:30 AM

                    @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
                    • T
                      Terry R
                      last edited by Jun 23, 2020, 3:32 AM

                      @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
                      3 out of 10
                      • First post
                        3/10
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors