My music library consists of folders named after the following pattern :
METAGENRE - Subgenre(s) - ARTIST - Album (year)
I want to switch the year and album "tags" in the folders' names for some bands/artists of whom I own the whole discography, so it gets sorted by chronological order of release instead of album name. I the meantime I can also remove the parentheses around the year tag, i.e.:
METAGENRE - Subgenre(s) - ARTIST - year Album
For instance : METAL - Black, Français - PESTE NOIRE - Split (2018)
Should become : METAL - Black, Français - PESTE NOIRE - 2018 Split
I only have a minimal experience with the shell. Looking for help here and elsewhere I could come up with this yet imperfect one-liner ("echo" is for testing prior to renaming and avoid potential hell, I also retranscribe on several lines here for readability) :
% for f in *PESTE\ NOIRE* ;
do echo
mv "$f"
"$(echo $f | sed `s/- ([A-Za-z]+) \(([0-9]{4})\)$/- \2 \1/p`)"
;
done
When running this command in the terminal, all I get is :
zsh: missing identifier after `+'
What am I doing wrong ?
EDIT: (using ' instead of ` quotes)
% for f in *PESTE\ NOIRE* ; do echo mv "$f" "$(echo $f | sed 's/- ([A-Za-z]+) \(([0-9]{4})\)$/- \2 \1/')" ; done
works but now I get another error:
sed: 1: "s/- ([A-Za-z]+) \(([0-9 ...": \2 not defined in the RE
Hence :
% for f in *PESTE\ NOIRE* ; do echo mv "$f" "$(echo $f | sed 's/- \([A-Za-z]+\) \\\(\([0-9]{4}\)\\\)$/- \2 \1/')" ; done
Returns no error, but the folder remains unrenamed.