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.0How would i delete everything except for the gift cards with the $100 balance
-
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 theRegular expression search
mode
Click on theReplace All
buttonHope this helps.
-
@astrosofista said in How do I delete a line with a certain number in it:
Search: (?-s)(^.= $100.0\R)|.\R
Replace: $1I 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.0How would I remove the “= $100.0” and only keep the numbers?
-
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".
-
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 theRegular expression search
mode
Click on theReplace 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
-
-
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 theRegular expression search
mode
Click on theReplace All
buttonAnd 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 type100\.0
(assuming search mode is regular expression, otherwise just100.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 thenon 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