I wrote a script which changes names of last downloaded songs and copy them to music directory. Can it be written better?
#!/bin/bash
IFS=$'\n'
for file in $(find "/home/stanek/Downloads/" -iname "*.mp3" -mtime -7 | sort)
do
nowy=$(echo $file \
| sed "s/_/ /g" \
| sed "s/\s*(*[A-z0-9.]*.pl)*//g" \
#leave brackets and text if it is remix
| sed "s/\(\s*(\s\?[A-z0-9 ]*remix)\)\|\s*(\s\?[a-z0-9. ]*)/\1/gi")
if [ "$nowy" != "$file" ]
then
echo "ZMIANA NAZWY DLA:"
echo $nowy
mv $file $nowy
fi
done
for file in $(find "/home/stanek/Downloads/" -iname "*.mp3" -mtime -7 | sort)
do
echo "I will copy: $file" | sed "s/\/home\/stanek\/Downloads\///g"
done
read -p "Is it ok? (y)" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
i=0
for file in $(find "/home/stanek/Downloads/" -iname "*.mp3" -mtime -7 | sort)
do
paste=$(echo $file | sed "s/\/home\/stanek\/Downloads\///g")
cp $file "/home/stanek/Music/$paste"
i=$((i+1))
done
echo "Copied $i files"