Então, aqui estão dois scripts, que você pode colocar em uma pasta com os arquivos pdf precisando ser renomeado.
O primeiro é para adicionar números de página e o segundo é para excluir eles. Ambos os scripts são interativos
- Digite abort Enter para sair do script,
- digite n Digite para entrar no modo interativo arquivo por arquivo
- e se você quiser que um script prossiga com todos os pdfs sem confirmação , digite y Digite y Enter .
O script para adicionar o número de páginas em file.pdf (file.pdf - > file [N] .pdf)
#!/bin/bash
IFS='
'
ret="not_ok";
renameinteractively () {
for file in *.pdf ; do
# derive number of pages in a pdf document
npages='pdfinfo $file | grep Pages | awk -e '{print $2}'';
# make up a new filename
file2=${file%%.pdf}[$npages].pdf;
# an auxiliary variable
ret="not_ok";
# interactive part. Ask to rename or not.
printf "Rename\n $file to \n $file2 ? (y/n/abort) \n";
until [ $ret == 'ok' ]; do
# read your answer and y-for rename, n-skip and abort-to exit
read ans;
if [ $ans == "y" ]
then
mv $file $file2;
ret="ok";
continue;
elif [ $ans == "n" ]
then
ret="ok";
break;
elif [ $ans == "abort" ]
then
exit;
else
printf "Enter 'y', 'n' or 'abort', please! \n\n";
fi
done;
done ;
}
renameallofthem () {
until [ $ret == 'ok' ]; do
if [ $a == "y" ]
then
for file in *.pdf ; do
npages='pdfinfo $file | grep Pages | awk -e '{print $2}'';
mv $file ${file%%.pdf}[$npages].pdf;
printf "\nMoved \n"
echo $file
printf "to\n"
echo ${file%%.pdf}[$npages].pdf
done ;
ret="ok";
exit;
elif [ $a == "n" ]
then
printf "\n\n OK, let's do it interactively!\n\n"
renameinteractively;
elif [ $a == "abort" ]
then
exit;
else
printf "Enter 'y', 'n' or 'abort', please! \n\n";
fi;
done;
}
printf "Rename ALL of the .pdf files in current folder? (y/n/abort) \n"
read a
if [ $a == "y" ]
then
printf "Really??\n\n Do we rename ALL of them? (y/n/abort) \n"
read a
renameallofthem;
elif [ $a == "n" ]
then
printf "\n\n OK, let's do it interactively!!\n\n"
renameinteractively;
elif [ $a == "abort" ]
then
exit;
else
printf "Enter 'y', 'n' or 'abort', please! \n\n";
fi
O script para remover o número de páginas do arquivo [N] [N] .... [N] .pdf (arquivo [N] [N] .... [N] .pdf - > file.pdf )
#!/bin/bash
IFS='
'
deleteNumbersInteractively () {
for file in 'ls *].pdf | grep '\[[0-9]*\]'' ; do
# an auxiliary variable
ret="not_ok";
# make up a new filename
file2='echo $file | sed -e 's/\[[0-9]\+\]//g' ';
# interactive part. Ask to rename or not.
printf "Rename\n $file to \n $file2 ? (y/n/abort) \n";
until [ $ret == 'ok' ]; do
read ans;
if [ $ans == "y" ]
then
mv $file $file2;
ret="ok";
continue;
elif [ $ans == "n" ]
then
ret="ok";
continue;
elif [ $ans == "abort" ]
then
exit;
else
printf "Enter 'y', 'n' or 'abort', please! \n\n";
fi
done;
done;
}
deleteAllTheNumbers () {
until [ $ret == 'ok' ]; do
if [ $a == "y" ]
then
for file in *.pdf ; do
file2='echo $file | sed -e 's/\[[0-9]\+\]//g' ';
mv $file $file2;
printf "\nMoved \n"
echo $file
printf "to\n"
echo $file2
done ;
ret="ok";
exit;
elif [ $a == "n" ]
then
printf "\n\n OK, let's do it interactively!\n\n"
deleteNumbersInteractively;
elif [ $a == "abort" ]
then
exit;
else
printf "Enter 'y', 'n' or 'abort', please! \n\n";
fi;
done;
}
printf "Delete ALL of the filename[NUMBERS].pdf from files in current folder? (y/n/abort) \n"
read a
if [ $a == "y" ]
then
printf "Really??\n\n Do we rename ALL of them? (y/n/abort) \n"
read a
deleteAllTheNumbers;
elif [ $a == "n" ]
then
printf "\n\n OK, let's do it interactively!!\n\n"
deleteNumbersInteractively;
elif [ $a == "abort" ]
then
exit;
else
printf "Enter 'y', 'n' or 'abort', please! \n\n";
fi
Está tudo bem agora?