Community
    • Login

    remove n lines before and after a specific text

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 1.9k Views 1 Watching
    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.
    • Rockberto ManentiR Offline
      Rockberto Manenti
      last edited by Rockberto Manenti

      Hi to all,
      I am not at all an expert in notepad ++ and above all in commands to find and replace words or phrases within a text. I would like to be able to delete, on several files, some lines before and after a line that contains a specific word (but leaving everything else before and after) . Example:

      text bla bla bla
      bla bla bla
      <actor>
      <name> Chuck Profus </name>
      <role> Drums </role>
      <order> 5 </order>
      <thumb></thumb>
      </actor>
      bla bla bla
      bla bla bla

      I’d like to delete 4 lines before and 1 after <thumb></thumb>
      and must become in all the files:

      text bla bla bla
      bla bla bla
      <thumb></thumb>
      bla bla bla
      bla bla bla

      It can be done? Thanks in advance

      1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn
        last edited by

        @Rockberto-Manenti

        You might try:

        Find: (?-s)(?:.*?\R){4}^(.*?<thumb></thumb>.*?\R).*?\R
        Repl: ${1}
        Search mode: Regular expression

        1 Reply Last reply Reply Quote 1
        • Rockberto ManentiR Offline
          Rockberto Manenti
          last edited by

          @Alan-Kilborn said in remove n lines before and after a specific text:

          ${1}

          seems that it works!!! many thanks!
          now I try on multiple files

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors