I am writing this bash script and i need to remove part of a string
Code:
#!/bin/bash
allTracks="/var/www/music/xml/tracks/all.xml"
touch "$allTracks"
echo "<allTracks>" >"$allTracks"
artistFilename="/var/www/music/xml/artists/all.xml"
touch "$artistFilename"
echo "<artists>" >"$artistFilename"
for level1 in *
do
echo "<artist Artist=\"$level1\" XMLLink=\"xml/artists/$level1.xml\"></artist>" >>"$artistFilename"
albumFilename="/var/www/music/xml/artists/$level1.xml"
touch "$albumFilename"
echo "<artist>" >"$albumFilename"
for level2 in "$level1"/*
do
echo "<album albumTitle=\"$level2\" XMLLink=\"xml/albums/$level2.xml\"></album>" >>"$albumFilename"
if [ -d "$level2" ]
then
if [ ! -e "$level1" ]
then
mkdir "/var/www/music/xml/albums/$level1"
fi
################################################## HERE
echo "<album albumTitle=\"$level2\" XMLLink=\"xml/albums/$level2.xml\"></album>" >>"$albumFilename"
trackFilename="/var/www/music/xml/albums/$level2.xml"
else
trackFilename="/var/www/music/xml/albums/$level1.xml"
fi
touch "$trackFilename"
echo "<album>" >"$trackFilename"
#parse each mp3 file for info and insert to xml file
if [ -d "$level2" ]
then
for title in "$level2"/*.mp3
do
mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$trackFilename"
mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$allTracks"
done
else
for title in "$level1"/*.mp3
do
mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$trackFilename"
mp3info "$title" -p "\n\t<track number=\"%n\" trackTitle=\"%t\" filename=\"mp3/%F\"></track>" >>"$allTracks"
done
fi
if [ -f "$level2" ]
then
echo "<album albumTitle=\"$level2\" XMLLink=\"xml/albums/$level1.xml\">" >>"$albumFilename"
fi
echo "</album>" >>"$trackFilename"
done
echo "</artist>" >>"$albumFilename"
done
echo "</allTracks>" >>"$alltracks"
echo "</artists>" >>"$artistFilename"
I put a comment where the problem is.
$title2 outputs to '$title1/*' where * is anything in folder '$title1'
i need to strip out everything before the '/' in $title2. i tried using sed with the 'D' opperand but couldn't get it to work. any help is much appreicated.
thanks in advance,
Phil V