Delete every line below a bookmarked line.
-
@dr-ramaanand If it were that easy, unfortunately, I have about: 200,000 lines where the # lines that I bookmarked have different names. I have managed to make a code that bookmarks all the ones I want to delete with the differences that I found. So now it is “only” the line under all the bookmarks that needs to be deleted. Then I re-bookmark those lines with # again and delete the bookmarked lines.
-
@Antheds-Kennel said in Delete every line below a bookmarked line.:Something went wrong at the end of my post, and I’m not allowed to correct it since it’s been 4 hours. So the Swedish part is still there, sorry. But it should be like this:
Your “Macro name” line looks like this:
<Macro name="DelUnderBookmarks" Ctrl="yes" Alt="no" Shift="yes" Key="121">
And mine looks like this:
<Macro name="DelUnderBookmarks" Ctrl="no" Alt="no" Shift="no" Key="0">
Could that be the difference?
So now it’s REALLY CLOSE to get it working, you’re a rock at this, you know, THANK YOU :) -
No, the only difference in that
<Macro name="..."...>
line is that mine had a keyboard shortcut assigned and yours did not. Remember, after editing the macro, you must save, exit Notepad++, and reload; and if you had done any other macro recording or keyboard shortcut setting in the same session where you edited the macro, you will have overwritten it, and you will need to re-edit, making sure to exit Notepad++ and start it again before editing and after saving and editing, otherwise it will be overwritten when Notepad++ exits.Unfortunately, from your posted data, I cannot tell what you had before you ran the macro, where your bookmarks were, and why what you got was different than what you expected. Without all that data, unambiguous, there is no way I can guess what went wrong.
My macro literally goes “move to next bookmark, toggle the bookmark off, go down one line, and delete the line”. If that is not the algorithm you want, then your previous descriptions have all been insufficient to say what you really want.
-
@PeterJones Hi and thanks for the quick reply. What I’m using is this one which I bookmarked lines 3,7 and 9:
#EXTINF: id="ABBA" name="ALBUM" group-title="Sweden" D:/MP3/Sweden/ABBA/The Album #EXTINF: id="ABBA" name="ALBUM" group-title="Denmark" D:/MP3/Sweden/ABBA/ABBA #EXTINF: id="ABBA" name="ALBUM" group-title="Sweden" D:/MP3/Sweden/ABBA/Ring ring #EXTINF: id="ABBA" name="ALBUM" group-title="Canada" D:/MP3/Sweden/ABBA/Voyage #EXTINF: id="ABBA" name="ALBUM" group-title="USA" D:/MP3/Sweden/ABBA/Super Trouper #EXTINF: id="ABBA" name="ALBUM" group-title="Sweden" D:/MP3/Sweden/ABBA/Waterloo
And I have closed Notepad++ before I change the files, I have been creating macros for several years and made that very mistake in the beginning where I did not close the program before. So the question is as I posted in my last post why your script deletes the last line that I do not want to delete. Otherwise it works great. With kind regards Thore
-
@Antheds-Kennel said in Delete every line below a bookmarked line.:
why your script deletes the last line that I do not want to delete.
It’s a macro, not a script, so it has no logic capability. I hadn’t noticed it doing that during my earlier tests, but I can reproduce. Essentially what happens is after the last bookmark (on what was originally line 9) is removed and it deletes the next line as it should have, it hasn’t reached the end yet, so searches for a bookmark again, and doesn’t find one, but still moves forward in the macro (because macros cannot have logic) and thus toggles the non-existent bookmark to “on”, then moves down a line, and deletes it, then it searches for the next bookmark which requires it to wrap around, finds one, toggles it, and deletes the next line, and keeps going through those accidental loops until the down-a-line finally reaches the end of the file.
As I tried to indicate earlier, it was entirely possible that a macro is not sufficient for your problem; we have now found the reason why. There might be a different way to construct the macro that would avoid that logic problem, but I cannot think of one. I really don’t think a macro is going to cut it.
You still haven’t explained why bookmarking the actual lines you want to delete, rather than the lines before the ones you want to delete, is not a valid solution: any search that you can use to automatically mark those lines could be easily modified to mark the line after the text rather than the line on your matching text, thus bookmarking the lines you want to delete (and in that case, you could just delete them from the search/replace, rather than bookmarking as one search then deleting in a separate macro action)… And if you’re manually bookmarking the lines, rather than doing it from the Mark dialog, you’re wasting a lot of time, because if you’re already there to mark it, you could just as easily do the deletion yourself.
So the right solution that I can see for you is: (1) if you are currently manually bookmarking, then just manually delete the next line; or (2) if you are bookmarking using the search-based Mark dialog, make a slight tweak to your search and use the Replace menu instead to immediately delete those. If you believe neither (1) nor (2) are sufficient for your needs, you will have to explain why, because I cannot see any reason why one of those two won’t work for the circumstances you’ve described. If you can come up with a meaningful reason, then I or someone else might be able to come up with a script for the PythonScript plugin that will have all the safety logic built in to follow your inefficient and illogical bookmark-the-wrong-line-then-delete-the-subsequent-lines-separately sequence that you seem to be insisting upon… but I still believe (1) or (2) would be better for you.
-
@PeterJones Hello again. THANK YOU for all the time you have put into this project, but I guess I’ll have to give up and give up. When someone like you says that this is difficult to solve in the way I thought I would, I have to give up unfortunately. I understand what you mean, but I don’t know how I’m going to do it, since there are 397,580 rows that I have to sort somehow. I thought I was on the right track when I managed to bookmark the row of the two that has groupings in it. The second row is just an address that is unique for each post. I thank you so much for all the help, you are super nice here. This was my first problem I have posted in this forum, and it is definitely not the last. I will use the ideas you have come up with on other occasions when I have saved them. Have a good time, with kind regards from a snow-white and icy Sweden.
-
@Antheds-Kennel said in Delete every line below a bookmarked line.:
since there are 397,580 rows
So that’s a good reason to avoid (1), but nothing you have said explains why you think (2) won’t work for you.
I have to give up
Don’t lie to yourself. If you give up, it’s your own choice. All the information you have given us says that (2) will work for you, but you are choosing to ignore that option without explaining why.
that I have to sort somehow.
This is the first you’ve mentioned sorting, that I noticed.
Until you accurately describe what you are actually wanting, no one can help you.