33 lines
720 B
Bash
Executable file
33 lines
720 B
Bash
Executable file
#!/usr/bin/env zsh
|
|
|
|
# get script directory
|
|
if [[ ${0[0]} = '/' ]]; then
|
|
scriptdir="${0:h}"
|
|
else
|
|
scriptdir="$PWD/${0:h}"
|
|
fi
|
|
|
|
cd $scriptdir
|
|
|
|
for rep in ??_*(/); do
|
|
print "renaming html of $rep"
|
|
cd $rep
|
|
i=10
|
|
for fic in *.html; do
|
|
title=$( <$fic grep h2 | sed 's/<[^>]*>//g;s/[^a-zA-Z]/_/g;s/__*/_/g;s/^_//;s/_$//')
|
|
if ((i<100)); then
|
|
num="0$i"
|
|
else
|
|
num="$i"
|
|
fi
|
|
((i+=10))
|
|
newfic=${num}_$title.${fic:e}
|
|
[[ $fic == $newfic ]] && { continue }
|
|
[[ -e $newfic ]] && {
|
|
print -- "$newfic already exists!" >&2
|
|
continue
|
|
}
|
|
mv $fic $newfic
|
|
done
|
|
cd $scriptdir
|
|
done
|