Hello everybody,
I've been trying (and trying...) to write this script, and now, i am at i point where i cannot go any further without any help from some (more experienced) users here
I'm a complete newbie on bash scripting, so be gentle
This is what i've come up so far:
Code:
./reading
.---------------------------------- - - -- -- -- --- - - - - - - - - - -
| Number of characters 48
| + Current: 107_david_guetta_-_missing_you_(feat._novel).mp3
| + Changed: 107_david_guetta-missing_you_(ft._novel).mp3
| + Matched: "(feat._" substitute "(ft._"
| + Morping: "107_david_guetta-missing_you_(feat._novel).mp3" to "107_david_guetta-missing_you_(ft._novel).mp3"
'-[END]---------------------------- - - -- -- -- --- - - - - - - - - - -
| Number of characters 69
| + Current: 108_david_guetta_-_choose_(feat._ne-yo_and_kelly_rowland)_(radio).mp3
| + Changed: 108_david_guetta-choose_(ft._ne-yo_and_kelly_rowland)_(radio).mp3
| + Matched: "(feat._" substitute "(ft._"
| + Morping: "108_david_guetta-choose_(feat._ne-yo_and_kelly_rowland)_(radio).mp3" to "108_david_guetta-choose_(ft._ne-yo_and_kelly_rowland)_(radio).mp3"
'-[END]---------------------------- - - -- -- -- --- - - - - - - - - - -
| + Changed: 108_david_guetta-choose_(feat._ne-yo_and_kelly_rowland)_(radio_edit).mp3
| + Matched: "(radio)" substitute "(radio_edit)"
| + Morping: "108_david_guetta-choose_(feat._ne-yo_and_kelly_rowland)_(radio).mp3" to "108_david_guetta-choose_(feat._ne-yo_and_kelly_rowland)_(radio_edit).mp3"
mv: cannot stat `108_david_guetta-choose_(feat._ne-yo_and_kelly_rowland)_(radio).mp3': No such file or directory
'-[END]---------------------------- - - -- -- -- --- - - - - - - - - - -
The problem is that it works with 1 variable to change, but when it uses 2 or more i'm getting errors (as stated above)
This is the code
It loads the variables from rsub file.
Code:
#!/bin/sh
numbers=*-* # * (wild card) matches everything between.
bpm=\(*bpm\).mp3
removenumeric=${mp3#$numbers}
removebpm=${mp3%%$bpm}.mp3
echo \.---------------------------------- - - -- -- -- --- - - - - - - - - - -
for mp3 in ls *.mp3; do
if [ -e "$mp3" ]
then
echo \| "Number of characters ${#mp3}"
echo \| \+ Current: ${mp3}
#replacing spaces with underscores, changing to lowercase
removed="$(echo ${mp3} | sed 's/ /_/g' | sed 's/_-_/-/g' | tr '[A-Z]' '[a-z]')"
if [ "$mp3" != "$removed" ] ; then
mv $mp3 $removed
while read inputline
do
match="$(echo $inputline | cut -d: -f1)"
substitute="$(echo $inputline | cut -d: -f2)"
corrected=$(echo $removed | sed 's/'$match'/''\'$substitute'/g')
if [ "$removed" != "$corrected" ] ; then
echo \| \+ Changed: $corrected
echo \| \+ Matched: \"$match\" substitute \"$substitute\"
echo \| \+ Morping: \"$removed\" to \"$corrected\"
mv $removed "$(echo $removed | sed 's/'$match'/''\'$substitute'/g')"
echo \'-[END]---------------------------- - - -- -- -- --- - - - - - - - - - -
fi
done < rsub
else echo Nothing to do!
fi
fi
done