In bash I want to parse filenames of mp3 files where the separator between track number, artist and title is " - " (space dash space). The expected result is as follows:
Title of the Track (Original Version - Long Edit)
My sed command as follows:
echo "03 - Artist name first-middle name - Title of the Track (Original Version - Long Edit)" | sed -E 's/^([^ - ]*[ - ]){2}//'
The result: Artist name first-middle name - Title of the Track (Original Version - Long Edit)
I'm stuck here and can't make " - " as one term. What am I doing wrong? Thanks for your hints!
Here sample data:
'01 - Skyway - Chillwave - Synthwave - Retrowave Mix.mp3'
'02 - Baldocaster - Astral Dive.mp3'
'05 - Jacket. and Shadowrunner - Deathtouch.mp3'
'06 - Night Drive - A Synthwave Mix.mp3'
'07 - Shadowrunner and Syst3m-Glitch - Eastbound Plane Mattaei (Original - Long Mix).mp3'
In the bash scriptI want to set the title variable as follows:
title=`echo ${filename} | sed -E "s/^([^${SEPARATOR}]*[${SEPARATOR}]){4}//"
where SEPARATOR is a variable as well containing e.g. " - "
A solution using parameter expensions.
$ filename="03 - Artist name first-middle name - Title of the Track (Original Version - Long Edit)"
$ filename="${filename#* - * - }"
$ echo "$filename"
Title of the Track (Original Version - Long Edit)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With