Page 1 of 1

SED question (Solved in a different way)

Posted: Mon Oct 26, 2020 2:23 pm
by taersh
Hi.

From a path and file name

Code: Select all

\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav
I need to remove this leading part

Code: Select all

\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\
How to do this?

Re: SED question

Posted: Mon Oct 26, 2020 4:37 pm
by fredx181
Hi Rainer, I think by escaping all the backward slashes, so gets double: \\

Code: Select all

echo "\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav" | sed -e 's|\\mnt\\sdb1\\LoopsAndSamples\\Movie_Score_Vol5\\||'
Works but maybe there's a more simple way.
EDIT: BTW are you sure the string/path has backward slashes? That's the Windows way.

Fred

Re: SED question (Solved in a different way)

Posted: Mon Oct 26, 2020 5:00 pm
by taersh
Thanks! :thumbup:

But how would I do it if the path is stored into a variable?
E.g.: BSPATH="\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav"

Yes, it has backslashes. It's content from a .sfz file.

Re: SED question

Posted: Mon Oct 26, 2020 5:26 pm
by Trapster
Maybe this?

Code: Select all

echo '\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav' | sed 's/\\/\//g' | xargs -n 1 basename
changes the backslashes to forward and then pulls the filename.

Re: SED question

Posted: Mon Oct 26, 2020 5:58 pm
by fredx181
But how would I do it if the path is stored into a variable?
E.g.: BSPATH="\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav"
I would understand the question if the leading part you want to remove is a variable :?

Maybe you can clarify some more about what exactly you do, If I understand correctly, you want the output:
Harp\Harp_a_1.wav

Fred

Re: SED question (Solved in a different way)

Posted: Mon Oct 26, 2020 6:24 pm
by taersh
Yes, I want to have only this part: Harp\Harp_a_1.wav or \Harp\Harp_a_1.wav remaining from the full path and name.

I want to change the full paths inside of a .sfz file.

So, the .sfz file should not search for the .wav file by full path, but related to its location.
The full path to the .wav file would be \mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav.
But I want to change that full path to relative path. So, Harp\Harp_a_1.wav or even \Harp\Harp_a_1.wav.

Example:

This: <region> lovel=1 hivel=127 sample=\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav
should change to
this: <region> lovel=1 hivel=127 sample=Harp\Harp_a_1.wav
or even to
this: <region> lovel=1 hivel=127 sample=\Harp\Harp_a_1.wav

Re: SED question (Solved in a different way)

Posted: Mon Oct 26, 2020 7:37 pm
by taersh
Thanks for the suggestions.

I could solve this another way.
Instead of submitting the full path of the samples to the program that creates the .sfz file, I'm jumping (cd ParentDir) into the parent directory and then submitting only the relative path of the samples to the program. So, by now the created <region> lines are all looking like this one:

Code: Select all

<region> lovel=1 hivel=127 sample=Harp\Harp_a_1.wav
Testing in Konfyt Keyboard Workstation resulted successful. The samples could be played by the UBS MIDI keyboard.

So, problem solved without to solve the SED question.

Re: SED question (Solved in a different way)

Posted: Tue Oct 27, 2020 2:20 am
by MochiMoppel
taersh wrote: Mon Oct 26, 2020 6:24 pm This: <region> lovel=1 hivel=127 sample=\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav
should change to
this: <region> lovel=1 hivel=127 sample=Harp\Harp_a_1.wav
FULL='<region> lovel=1 hivel=127 sample=\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav'
REMOVE='\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\'
echo ${FULL/"$REMOVE"}

Re: SED question (Solved in a different way)

Posted: Tue Oct 27, 2020 2:19 pm
by taersh
@MochiMoppel
Since I'm not getting any final success in my development I'm going to use your suggestion.
It's closer to my basic idea and might help on where I'm currently hacking now for hours without having any remarkable progress.

Thanks! :thumbup2:

Re: SED question (Solved in a different way)

Posted: Sun Nov 22, 2020 12:10 pm
by stemsee

ugly solution using g/awk

Code: Select all

echo "\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav" | gawk -F'\' '{$1=""; $2=""; $3=""; $4=""; print $0}' | cut -c4-$$ | tr ' ' '\\'

Re: SED question (Solved in a different way)

Posted: Sun Nov 22, 2020 3:01 pm
by stemsee
taersh wrote: Mon Oct 26, 2020 5:00 pm

Thanks! :thumbup:

But how would I do it if the path is stored into a variable?
E.g.: BSPATH="\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav"

Yes, it has backslashes. It's content from a .sfz file.

Code: Select all

BSPATH="\mnt\sdb1\LoopsAndSamples\Movie_Score_Vol5\Harp\Harp_a_1.wav"
echo "$BSPATH"  | rev | cut -d'\' -f1,2 | rev