delete line between bookmark
-
Hindsight looking at the script:
Where I call the
lower
function on theuser_input
variable probably isn’t the best place for it. They won’t fail with aValueError
and thus probably shouldn’t be part of that block. But the script DOES work as written (AFAICT), so I won’t provide a changed version. -
@pinuzzu99, @alan-kilborn All,
Sorry, I did not understand your need, correctly ! Indeed, you simply want, from a line, containing an e-mail address, delete all subsequent lines till the next line containing an e-mail address, excluded, don’t you ?
If so :
-
Move to the line right after a line containing an e-mail address
-
Manually
-
Using the regex
(?-s).+@.+\R\K
, which places the caret at beginning of any line right after an e-mail address
-
-
Now, use the following regex S/R to delete all lines till the next e-mail address line
-
SEARCH
(?s).+?(?=(?-s)^.+@)
-
REPLACE
Leave EMPTY
-
Note : I gave it a try, with
30,000
random lines between two lines containing an e-mail address and it correctly selected all this stuff in between and deleted it ;-))Best Regards,
guy038
-
-
tanxs Alan, this was what i wanted!
and the bookmarks were only to make it clear the range i wanted to eliminate…@guy038
tanxs for your reply. but i was hoping it could be done in one step…
anyway work well, always thanks for your appreciated help! -
@pinuzzu99 said in delete line between bookmark:
but i was hoping it could be done in one step
This implies that it is something you do often, so it might be worth recording multiple steps into a “macro” that you keep. This thread talks more about that.
Script notes: Using
bof
doesn’t make much sense – it is always going to be line 1 so why not just use1
? Also, I’ve thought of some extensions to the script. I could see myself using the script often. I’ll posts an enhanced version soon! -
tanxs for your explanation on macros.
but, if i understand correctly, if i record a macro, for example by deleting lines 10 to 20, this macro always repeats the same procedure…
I instead have different txt, in which the lines to be deleted are always different…
so i think in my specific case the elimination steps have to be done manually.
is this correct? -
@guy038
also your string work, but this delete all line, including line which contains the email…
instead i want delete the lines under the email, but leave this … -
I thought we were talking about several replacement operations when I brought up recording in macros. Other operations don’t lend themselves so well to “macroization”.
-
Hello, @pinuzzu99 and All,
You said in a previous post :
also your string work, but this delete all line, including line which contains the email…
instead i want delete the lines under the email, but leave this …My method does not delete any -mail address, assuming that you put the caret at the beginning of the first line, right after the line containing this e-mail address !
Consider the input text :
.... .... .... jasortrtn25hoon@hotmail.com:bartrall2335 2017-07-08 12.35.03_5.jpg 32KB 08/07/2017 19:34:57 2017-07-08 12.35.03_8.jpg 71KB 08/07/2017 19:34:57 2017-07-08 12.35.10_4.jpg 70KB 08/07/2017 19:35:04 2017-07-08 12.48.43_15.jpg 84KB 08/07/2017 19:48:41 2017-07-25 01.22.59.jpg 102KB 25/07/2017 08:22:59 ====================================== skysfsfff@gmail.cam:ksddsfdsfy37 .... .... ....
-
If you run the search regex
(?-s).+@.+\R\K
, the caret should have moved at the beginning of the line2017-07-08 12.35.03_5.jpg
, with the calltip^zero length match
-
Then, after running the search regex
(?s).+?(?=(?-s)^.+@)
all the lines, after thejasortrtn25hoon@hotmail.com
, till the second e-mail addressskysfsfff@gmail.cam
excluded, should have been selected, then deleted after replacement !
But, may be, you’ll prefer this other method, which need one operation, only !
-
Move , first, to a line containing an e-mail address, if necessary. Note that the caret can be at any position in that line, with an e-mail address !
-
Then, use the following regex S/R to delete all lines, after this
1st
e-mail address till the next e-mail address, excluded
SEARCH
(?-s).*\R\K(?s:.+?)(?=^.+@)
REPLACE
Leave EMPTY
Cheers,
guy038
-
-
with first string work fine, but at one specific account all text it is selected, then deleted! but only in a specific case, maybe it contains characters that other accounts don’t contain …
try with this txt: https://www.upload.ee/files/11106151/try_this.txt.htmlso, second string work, select all line that I want to eliminate, but then with the replace the lines are not deleted!
i have record my screen, see video here: https://www.upload.ee/files/11106092/video_02.mp4.html
maybe i do something wrong… -
@pinuzzu99 and All,
Oh… I forgot to mention that you need to use the
Replace All
button , only. Do not use theReplace
button which does not act as it should, when the regex contain any\K
syntax. This is a general rule, available for any regex containing, at least, one\K
syntaxBest Regards,
guy038
-
yes i know, Replace All and i have try it before my post above, but as i said, i want check all my single block one by one before delete all lines.
for my purpose work fine this: (?-s).*\R(?s:.+?)(?=^.+@)
without \K and work with Replace, but on next block i need to put cursor at begin line under mail line…
this is little problem if my txt have 10,000 block of mail - file list… -
in this specific case string (?-s).*\R(?s:.+?)(?=^.+@) don’t find value…
why? what is different than other blocks?earlnathanieluhftr@gmail.com:natchel7634 Used: 3/50GB Physiology 0KB Internal Med 0KB Passwords.zip 370KB Lippincott Illustrated Reviews Flash Cards Physiology - Preston, Robin [SRG].pdf 42137KB 08/09/2015 17:46:42 Ganongs Review of Medical Physiology, 24E (2012) [UnitedVRG].pdf 80607KB 08/09/2015 17:46:36 Kaplan USMLE Step 1 Physiology Lecture Notes (2013) [PDF] [UnitedVRG].pdf 25312KB 08/09/2015 12:50:40
-
@pinuzzu99 said in delete line between bookmark:
i want check all my single block one by one before delete all lines.
But as @guy038 said, that expression won’t work in one-at-a-time mode. Continuing to try is an exercise in futility.
If you are uncertain whether the regex will meet all your needs, and you want to be able to compare the “before” and “after” states of your file, I recommend opening the original file
blah.txt
, File > Save copy as, give it a name likeblah_new.txt
, then openblah_new.txt
and move to other view – so that the two panes of Notepad++ areblah.txt
on the left andblah_new.txt
on the right, then run Guy’s regex on theblah_new.txt
, then use the Compare plugin (which you can install from the Plugins Admin) to find and easily navigate through the differences between the files, and make sure everything is the way you want it. If they are all right, great; if most are right and just a couple aren’t quite right, then manually fix those last few; if there are many wrong, then run Undo, and try to update the regex to better do what you want. Once you are happy withblah_new.txt
, you can delete the originalblah.txt
(or rename toblah_old.txt
, then renameblah_new.txt
toblah.txt
.(Or, you can start by copying
blah.txt
toblah_old.txt
, and haveblah_old.txt
on the left andblah.txt
on the right, doing all your edits toblah.txt
, and eliminating the extra renames at the end of the procedure.) -
i already save one backup of my txt…
and yes, compare plugin, i have and already use this.
however Document Map is very useful for scrolling through the file… -
i hope guy038 reply to my post (4 post above above this post)…
-
Hello @pinuzzu99, @Peterjones, @alan-kilborn and All,
Sorry, I did not even notice this post, which was rather short ;-)) Well, I suppose that the regex does not work because the last line
Kaplan USMLE Step 1 .....
is not followed with an e-mail address but is just the very end of your file !In order that this specific case will be taken in account, too, here is a other search regex :
-
Move to any line containing an e-mail address
-
Open the Search dialog (
Ctrl + F
) -
SEARCH
(?-s).*\R\K(?s:.+?)(?=^.+@|\z)
-
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
Click on the
Find Next
button -
Hit the
ESC
key to close the Find dialog -
Now, hitting, repeatedly, on the
F3
key, it will select all text, after this e-mail address till the next e-mail address excluded and so on… OR till the very end of current file ! -
Of course, you may manually delete some of these blocks, with the
Delete
key, if necessary -
For a global suppression, leave the replacement zone
empty
and click on theReplace All
button
Moreover, if you want to move from one e-mail address to the next or the previous one, here is an simple method :
-
Open the Mark dialog (
Search > Mark...
) option -
SEARCH
@
-
Tick the
3
optionsBookmark line
,Purge for each search
andWrap around
-
Click on the
Mark All
button
=> Now, you can easily navigate betweens all these email addresses, using the
F2
and/orShift + F2
shortcutsBest Regards,
guy038
-
-
oh guy038 tank you so much for your reply! you are my super-hero!
2 really interesting things. it was what i wanted! many tanxs.only little curiosity: at the first part of your reply, about this code
(?-s).*\R\K(?s:.+?)(?=^.+@|\z)
work fine for my purposes, but i don’t understand why if i click (after the text block after mail has been selected) Replace with:empty
don’t delete simply this block… i have to exit thefind
and delete it manually with theDEL
key.
it would be very nice to remove the block with theReplace with
key… it’s not possible that?? -
…again… guys038 where did you end up ??
does not exist here in the forum the possibility to send a PM to a user? I do not think so…
-
Time to sit down and do some LEARNING and stop doing so much ASKING ?
-
dear sir… if i knew how to do it, I wouldn’t be here to waste time and ask others for advice, don’t you think?
think before writing, your speech is not welcome.
please avoid writing in my posts, your post is not required.
THANK YOU