Replace value according to previous line
-
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
-
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 Expressionsearch 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 ) -
\Ris any End of Line (\r\nfor a Windows file,\nfor an Unix file or\rfor 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 =
\1Notes :
-
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
\Kform, 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
-
-
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
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