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



  • 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



  • 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.



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



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



  • @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".



  • 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



  • 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



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



  • @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.



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


Log in to reply