Community
    • Login

    How do i remove a duplicate line after a particular combination?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 446 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.
    • Tasos AkridoT Offline
      Tasos Akrido
      last edited by Tasos Akrido

      Let’s say i have this in my notepad:

      <path>./gamename1567/gamename1567.cue</path>
      <image>C:/images/gamename1567/gamename1567.png</image>
      

      And i want to do this:

      <path>./gamename1567/gamename1567.cue</path>
      <image>C:/images/gamename1567.png</image>
      

      You can see the “gamename” is mentioned twice in the <path> section and i need that as is. But i want the second “gamename” removed if it’s in the <image> section.

      There are thousands of lines with different “gamenames” in that text file. So i can’t just replace

      “gamename1567.png</image>”

      with

      “</image>”

      Because that will affect only one game in the list. I’m stuck!

      1 Reply Last reply Reply Quote 0
      • guy038G Offline
        guy038
        last edited by

        Hello, @tasos-akrido and All,

        Very easy with regular expressions !

        • Open the Replace dialog ( Ctrl + H )

        • SEARCH (?-s)^(\h*<image>C:/images)/.+(/.*\.png</image>)

        • REPLACE \1\2

        • Tick, preferably, the Wrap around option

        • Select the Regular expression search mode

        • Click once on the Replace All button or several times on the Replace button

        Voila !

        So, for instance, the text :

        <path>./gamename1567/gamename1567.cue</path>
        <image>C:/images/gamename1567/gamename1567.png</image>
        
        <path>./gamename37/gamename37.cue</path>
        <image>C:/images/gamename37/gamename37.png</image>
        
        <path>./gamename12345/gamename12345.cue</path>
        <image>C:/images/gamename12345/gamename12345.png</image>
        

        would be changed into :

        <path>./gamename1567/gamename1567.cue</path>
        <image>C:/images/gamename1567.png</image>
        
        <path>./gamename37/gamename37.cue</path>
        <image>C:/images/gamename37.png</image>
        
        <path>./gamename12345/gamename12345.cue</path>
        <image>C:/images/gamename12345.png</image>
        

        In addition this regex S/R can also manage this case :

        <path>./gamename1567/aaaaa/bbbbb/ccccc/gamename1567.cue</path>
        <image>C:/images/gamename1567/aaaaa/bbbbb/ccccc/gamename1567.png</image>
        

        And, after replacement, you would get :

        <path>./gamename1567/aaaaa/bbbbb/ccccc/gamename1567.cue</path>
        <image>C:/images/gamename1567.png</image>
        

        Nice, isn’t it ?

        Best regards

        guy038

        1 Reply Last reply Reply Quote 2
        • Tasos AkridoT Offline
          Tasos Akrido
          last edited by

          Thank you, it works :)

          1 Reply Last reply Reply Quote 1

          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