#!/bin/bash
FAJL="$1"
if [ -z "$FAJL" ]; then
echo "Parametr neuveden, predpokladam *.avi";echo
FAJL="*.avi"
fi
EXT=${FAJL##*.}
ls -1 $FAJL | sort -n > /tmp/series-ren.tmp
if [ -r names.txt ]; then
if [ "$(wc -l <names.txt)" -ne "$(wc -l </tmp/series-ren.tmp)" ]; then
echo "Pocet souboru v names.txt nesouhlasi s poctem souboru odpovidajicim $FAJL."
exit 1
fi
iconv -f "UTF-8" -t "ascii//TRANSLIT" "names.txt" | sed 's/ /-/g;s/ /-/g' > "/tmp/series-ren.names"
cat /dev/null > redo.log
while read -r FILENAME && read -r NEWNAME <&3; do
read NUMB FNAME <<< $NEWNAME
NEWNAME=${NUMB}_${FNAME}
echo "$FILENAME $NEWNAME" >> redo.log
mv "$FILENAME" "$NEWNAME.$EXT"
done </tmp/series-ren.tmp 3</tmp/series-ren.names
else
echo "Nenalezen names.txt, nemam co delat!"
exit 1
fi