Community
    • Login

    Replace value according to previous line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 4.3k 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.
    • geoslakeG Offline
      geoslake
      last edited by

      Hi guys

      Im editing sfz (a music samples standard), and would need to edit that kind of thing :

      *<region> sample=Samples\Blister Pack5\Baghhopen.wav
      lokey=0
      hikey=0
      pitch_keycenter=60

      <region> sample=Samples\Blister Pack5\Bagsnes1.wav
      lokey=1
      hikey=1
      pitch_keycenter=60

      <region> sample=Samples\Blister Pack5\Bagsnes2.wav
      lokey=2
      hikey=2
      pitch_keycenter=60*

      etc etc (hundreds of values)
      What i need to do is knda simple i guess, i need the xx value for “pitch_keycenter=” to be set according to what previous line say (hikey=yy)
      In this case i would need to respectively set the “pitch_center” values, to 0,1 and 2.
      Is there a way to achieve this in np++ ?

      Thanks a million

      CHeers

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

        Hello Emmanuel,

        Well, it’s easy enough to achieve that S/R !

        • Go back to the very beginning of your file

        • Open the Replace dialog and choose the Regular Expression search mode

        • In the SEARCH zone, type ((\d+)\Rpitch_keycenter=)\d+

        • In the REPLACE zone type \1\2

        • Click on the Replace All button

        Notes :

        • \d+ represents any number (one or more consecutive digits )

        • \R is any End of Line ( \r\n for a Windows file, \n for an Unix file or \r for an old Mac file

        • The regex (\d+)\Rpitch_keycenter= stands for the group 1, which is re-written, first, (\1), in replacement

        • The first regex \d+ is the group 2 ( the number at the end of the hikey line, before the EOL and pitch_keycenter ), which is re-written, last, (\2), in replacement


        You can either use that other regex syntax :

        SEARCH = (\d+)\Rpitch_keycenter=\K\d+

        REPLACE = \1

        Notes :

        • The regex engine tries to match the regex (\d+)\Rpitch_keycenter=, and \d+ is the group 1 ( the number at the end of the hikey line

        • Then, due to the \K form, the regex engine forget the previous match and tries, now, to match the remaining. That is to say, the simple regex \d+ ( the number, at end of the pitch_keycenter line )

        • This number is, finally, replaced by the value of group 1

        • DON’T use the step-by-step Replace button, with that second syntax

        Hope these regexes will be useful to you !

        Best Regards

        guy038

        1 Reply Last reply Reply Quote 0
        • geoslakeG Offline
          geoslake
          last edited by

          Wow, thank you very very much, guy038, you not only almost saved my life :), but you took the time to explain things extensively to me, thanks again !

          Cheers

          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