Community
    • Login

    Delete whole line based on search

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 2.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Omar KO
      Omar K
      last edited by

      I have a file with a few hundred lines. There is a specific text in some lines which can be used to identify which lines to remove.

      I tried recording a macro by searching for the word “KRA” and then deleting the entire line but when I run the Macro, it only removes the word KRA from the lines.

      I’m very new to macros so I can’t really troubleshoot it, has anyone recorded a macro like this previously and can provide some suggestions on how to delete the whole line based on the search result or if the line has a specific word in it?

      1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R
        last edited by Terry R

        @Omar-K
        A better option is to use the “Mark” feature. So under main menu “Search” look for Mark.
        On the Find What field type in what you are searching for. You can use the search mode as “Normal”, that way it means you are explicitly searching for some text, rather than using a regular expression to search.
        Make sure the “bookmark line” is ticked, also have “wrap around” ticked. Then click on the “Mark All” button. Now every line that has that text in it will have a blue circle at the start of the line (default marker) denoting that line has the text.
        Before removing the lines, you may want to check some to be certain they haven’t picked any lines you did NOT want deleted.
        Once confirmed use the main menu “Search”, then “Bookmark” then “Remove Bookmarked Lines”.

        This is a far easier method than using a regex (regular expression) or using a macro to remove a line.

        Terry

        1 Reply Last reply Reply Quote 2
        • Omar KO
          Omar K
          last edited by

          Thanks Terry. That’s exactly what I was looking for. Just couldn’t see the Remove Bookmarked Lines option where I looked.

          Appreciate the quick response.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors