Select/mark all lines which contain a certain pattern and add the line above



  • There is already a topic but I wanted to start a new thead to “add the line above”:
    https://community.notepad-plus-plus.org/topic/14704/select-mark-all-lines-which-contain-a-certain-pattern

    I’m not sure how to copy a line using the bookmark feature yet, but I want a bookmark to be added to every line above what I have already bookmarked as a result of edit>find>mark>bookmark line>mark all.



  • @sgtsixpack said in Select/mark all lines which contain a certain pattern and add the line above:

    how to copy a line using the bookmark feature

    Search menu > Bookmark > Copy Bookmarked Lines

    I want a bookmark to be added to every line above what I have already bookmarked

    You can’t do this based solely on the bookmarks. You can, however, craft a mark search expression that will bookmark a line of interest and the line above that one.



  • If you have already created YOURREGEX to mark data, if you want to bookmark the line it is on plus the line above, you could use a Find what box of:

    (?-s)^.*\R.*? and then append YOURREGEX to that.

    Example: Bookmark line containing foo and then line above it:

    Also: (?-s)\R.*?foo works but there will only be a bookmark on the “line above”, no red coloring of the text. I like the red coloring so I prefer the first version.



  • I just expanded my search to include the line above, not sure if this is what you meant. I don’t know about “craft an expression”. I also have no clue about your last reply. My problem is solved though so thanks.



  • @sgtsixpack said in Select/mark all lines which contain a certain pattern and add the line above:

    I don’t know about “craft an expression”
    I also have no clue about your last reply.

    Sorry, I should have been more explicit.
    My comments were in regard to “Regular Expression” Search mode, which is typically what one is inferring when they ask “how can I manipulate data that is relative to some other data”.

    As you’ve probably discovered, you can, in Normal Search mode, bookmark the “line above” by making a selection that covers both lines, perhaps partially, and then pressing ctrl+f go get your text in the Find what box. You can then switch the Find window to the Mark tab and proceed with bookmarking.

    But if you do it that way, you aren’t truly doing “line above”, you’re doing “line of” and “line below”. :-)


Log in to reply