SED question (Solved in a different way)

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
taersh
Posts: 951
Joined: Tue Jul 07, 2020 11:13 pm
Location: Germany
Has thanked: 53 times
Been thanked: 119 times

SED question (Solved in a different way)

Post 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?
Last edited by taersh on Mon Oct 26, 2020 7:37 pm, edited 1 time in total.

My Music:
https://soundcloud.com/user-633698367
Using my own build of Bionic64
The far-left is as fascist as the far-right is!

User avatar
fredx181
Posts: 2648
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 293 times
Been thanked: 1039 times
Contact:

Re: SED question

Post 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
User avatar
taersh
Posts: 951
Joined: Tue Jul 07, 2020 11:13 pm
Location: Germany
Has thanked: 53 times
Been thanked: 119 times

Re: SED question (Solved in a different way)

Post 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.
Last edited by taersh on Mon Oct 26, 2020 7:38 pm, edited 1 time in total.

My Music:
https://soundcloud.com/user-633698367
Using my own build of Bionic64
The far-left is as fascist as the far-right is!

Trapster
Posts: 149
Joined: Sat Aug 01, 2020 7:44 pm
Has thanked: 1 time
Been thanked: 40 times

Re: SED question

Post 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.
User avatar
fredx181
Posts: 2648
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 293 times
Been thanked: 1039 times
Contact:

Re: SED question

Post 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
User avatar
taersh
Posts: 951
Joined: Tue Jul 07, 2020 11:13 pm
Location: Germany
Has thanked: 53 times
Been thanked: 119 times

Re: SED question (Solved in a different way)

Post 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
Last edited by taersh on Mon Oct 26, 2020 7:38 pm, edited 1 time in total.

My Music:
https://soundcloud.com/user-633698367
Using my own build of Bionic64
The far-left is as fascist as the far-right is!

User avatar
taersh
Posts: 951
Joined: Tue Jul 07, 2020 11:13 pm
Location: Germany
Has thanked: 53 times
Been thanked: 119 times

Re: SED question (Solved in a different way)

Post 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.

My Music:
https://soundcloud.com/user-633698367
Using my own build of Bionic64
The far-left is as fascist as the far-right is!

User avatar
MochiMoppel
Posts: 1133
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 18 times
Been thanked: 368 times

Re: SED question (Solved in a different way)

Post 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"}
User avatar
taersh
Posts: 951
Joined: Tue Jul 07, 2020 11:13 pm
Location: Germany
Has thanked: 53 times
Been thanked: 119 times

Re: SED question (Solved in a different way)

Post 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:

My Music:
https://soundcloud.com/user-633698367
Using my own build of Bionic64
The far-left is as fascist as the far-right is!

User avatar
stemsee
Posts: 658
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 0
Has thanked: 162 times
Been thanked: 104 times
Contact:

Re: SED question (Solved in a different way)

Post 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 ' ' '\\'
User avatar
stemsee
Posts: 658
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 0
Has thanked: 162 times
Been thanked: 104 times
Contact:

Re: SED question (Solved in a different way)

Post 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 
Post Reply

Return to “Programming”