multiple search and remove
-
does notepad++ support multiple find and if line/word found then delete?
I’ve looked up and found some ways to done it with regex but it does not work in my case ( my lines contains so much long characters more than 64 per line and dots…
-
@handa-flocka said in multiple search and remove:
does notepad++ support multiple find and if line/word found then delete?
Yes, it is called a replacement operation (the “delete” part is replacement with “nothing”).
@handa-flocka said in multiple search and remove:
I’ve looked up and found some ways to done it with regex but it does not work in my case ( my lines contains so much long characters more than 64 per line and dots…
Well, no one can help you with a problem description like that. See HERE for some guidelines with which to better state your problem.
-
@alan-kilborn Thanks,
I have more than around 8k lines on my file, looking to remove around 500 ones.
my example lines:
ABC.123 ABCD.1234 ABCDF.12345
Looking to delete these two lines
ABCD.1234 ABCDF.12345
the outcome only the lines/words that are not found in the file will stay
(just as simple as find certain words then if the word/line exists, delete) -
the outcome only the lines/words that are not found in the file will stay
Both your original problem statement and your examples in your follow-up do not give a reasonable picture of your one sentence description (or vice versa). And it’s nonsensical: How do you delete words from a file not found in that same file?
Unless you mean, as I think you do, that you have two files: you are editing file1, and you have a list of words in file2, and you want to delete all the lines from file1 that contain a word from file2.
If that’s your actual problem statement, the simple answer is that regular expressions (built-in search/replace actions) cannot automatically reference words from file2 while editing file1. The regex engine is restricted to acting on a single file.
The medium answer is that with a medium-ish list of words, you can join the lines of file2 into part of the FIND for the search/replace in file1. With longer, it’s possible to bring the words of file2 into the bottom of file1, and use some tricks to get it to delete lines that contain those words. For full details, see previous discussions on virtually the same topic, such as https://community.notepad-plus-plus.org/topic/19380/use-text-file-to-remove-lines
caveat emptor
This advice in previous discussions works in general, for similarly-stated problems, based on my understanding of your issue, and is linked here to help you learn how to do this. I make no guarantees or warranties as to the functionality for you. You are responsible to save and backup all data before and after running this advice. If you want to use it long term, I recommend investing time in adding error checking and verifying with edge cases, and making sure that not too much is deleted from your file. You are responsible for your own data.
-
@peterjones Thanks,
I should’ve not mentioned files it made this a little bit confusing (I have only file),
alright I will point this in a more simpler way
example text (orignal)
cup trophy mug cupboard
I am looking to delete multiple words from the text without having to find and replace every time example: I am looking to delete word ( mug, and cupboard ) to get the outcome:
cup trophy
instead of doing simple find and replace with nothing for each word, I am looking to do it all at once
look up for every ( mug, and cupboard ) at the same time replace with nothingI think there might be some regex codes to do this but in my case my actual lines are much longer than the example above (with over 30 character per line which I think notepad++ wouldn’t fit in the find/search box )
-
I still don’t think you’re formulating your question and data well yet, but let’s press on. Also, please don’t change your data right in the middle of trying to ask your question.
But…ok…for your
cup
,trophy
data…find what:
^(mug|cupboard)\R
replace with: make sure this box is empty
mode: regular expressionwith over 30 character per line which I think notepad++ wouldn’t fit in the find/search box )
The length of data you can put in the find-what and replace-with boxes is actually quite long, 2046 characters I think, so you have some room to work.
-
This post is deleted! -
@alan-kilborn Thanks
that’s my point but the difference in here that is my original text has a quiet high number of characters
original sample:
MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6 ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075 MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
fitting 100+ of these characters is a bit high for a 2046 box, is there any other way to achieve this?
thank you
-
Hello, @handa-flocka, and All,
Well, @handa-flocka, you gave us an original sample of your file :
MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6 ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075 MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
OK ! Now, which characters or lines should be marked, deleted or replaced with other stuff, from your example ???
BR
guy038
-
@guy038 hello
will go with the first 6 lines from the file above (original) “find and delete.”
1-MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6 2-ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s 3-MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK 4-NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O 5-NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY 6-MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075 7-MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx 8-NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- 9-ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR 10-OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
the get the outcome
7-MjQ5NDI5MzgzMzQ3MTUzMDE2.G2uVES.-8pra1RI5TPOtMo0BDlQekL4mnx 8-NzIxNDY0ODA2ODgwNzU3Mzkz.AAoT1D.AGLYSncFvm8iKBlQuXfabRVprZ- 9-ODgyNjU1NzQ4OTg0OTk2NDYz.LO9ibu.HnBjcEiobV3QLWlKDdvPxOrZpIR 10-OTYwMTY3NjQyMzkzMzE0NDM0.TJPWbq.Pfca28AZmxeM-uqEVi6j1HkFn_K
now if I tried @Alan-Kilborn regex code it will actually work, but it wouldn’t fit notepad++ search/find box, and the actually number I am looking to delete in my file is more than 500+
i guess there might be some python code that somebody has already made or some feature in notepad++ that I am missing would do trick
thanks
-
@handa-flocka said in multiple search and remove:
fitting 100+ of these characters is a bit high for a 2046 box, is there any other way to achieve this?
You may be able to shrink it down… for example, if the six characters between the periods were unique, you might be able to do something like
^.*\.(B3G_W0|XqCHPX|HlytHz)\..*$(\R|\Z)
… but that’s not likely enough.At this point, a scripting solution is you best choice.
i guess there might be some python code that somebody has already made or some feature in notepad++ that I am missing would do trick
Oh, good, you’re willing to use pythonscript. I know that years ago, when we’d get questions like this, someone wrote a script that will look for all the lines in file2 and delete those lines from file1, but after 10 minutes of searching, I gave up and just wrote the slightly simpler script, where you manually populate the array in
list_of_strings
in the script, and then it will search for each of the texts in that array, and delete any lines in the active file that contain that string. If you want to also read all the lines from editor2 to populate thelist_of_strings
array, that’s simple enough to do, but I’ll leave it as an exercise to the reader; if you need help, show us what you tried, and we can point you in the right direction.# encoding=utf-8 """ in response to https://community.notepad-plus-plus.org/topic/22331/multiple-search-and-remove You can run this script, and it will delete all the lines in the active file that contain that text (even if it's as a substring). You can comment/uncomment lines in the script to make it match only whole lines (so the string "blah" would only match "blah", not "something blah something") You could modify it to read editor2 contents and then delete matching lines in editor1, but I will leave that as an exercise for the reader. Populate the list_of_strings array below, then run this script. The text in each line will be treated as a literal string, so regex characters will not be treated as regex (ie, dot will match a dot, not any single character). """ class forum_post22331: list_of_strings = [ 'MTkxMTMxOTkyMzcxNzg5ODcy.B3G_W0.pOFRk4TGe_SPNUhKrb58IVJvty6', 'ODY5NjU0MDYwNzkyOTM5NTEw.XqCHPX.bNW7X8fayguYEnVBmRkMvejlG4s', 'MjY4MzU4MjQwMTMyMTE3ODky.HlytHz.JOehsSFExPn1T_7RkoQq8LrZwjK', 'NDY4MTMxOTg5NjE2NjI1NjUz.ZvEGgz.3tHiZ80sc64WyQV5fr-Fklhax_O', 'NjUwNzM1Mzc3MzA0MDk1OTgd.Pr75Ph.JtTLUwxZWHaqc5jmvoueS0h6KGY', 'MTgzNTY4ODkyODAxMDMwOTE5.FKIb9Z.41SZmRhuPVXYAtienEsH2pG6075' ] def runme(self): editor.beginUndoAction() for search_string in self.list_of_strings: # uncomment the regex_string below that matches your desired behavior: regex_string = r'(?-is)^.*\Q' + search_string + '\E.*$(\R|\Z)' # match the string anywhere on the line in the active file #regex_string = r'(?-is)^\Q' + search_string + '\E$(\R|\Z)' # match the string only if it matches the whole line in the active file editor.rereplace(regex_string, "") editor.endUndoAction() if __name__ == '__main__': forum_post22331().runme()
-
-
@peterjones Thank you so much, much appreciated
it works, and somehow it should be included into notepad++ future -
@handa-flocka said in multiple search and remove:
somehow it should be included into notepad++ future
No, it shouldn’t.
-
Hello, @handa-flocka, @peterjones, @alan-kilborn and All,
Just tried your script, Peter and it wokrs like a charm ! Of course, the list of strings can be displayed in any order !
Now, regarding your attempt to find a previous script, on this topic, maybe it could be related to this @ekopalypse’s script :
https://community.notepad-plus-plus.org/post/57173
and the @alan-kilborn’s subsequent modification :
https://community.notepad-plus-plus.org/post/57229
Changes are, of course, needed to fit this present topic !
BR
guy038