renomeia múltiplos arquivos com uma variável

1

Estou tentando renomear um arquivo com uma variável.

Exemplo: 2014.001.**.**.**.D890.E.m a IP.PMST..BHE.D.2014.001 .

Meu script é:

#!/bin/bash

cd /home/pintolcv/Downloads

for jd in {001..366}
do

mv 2014.$jd.*.*.D890.E.m IP.PMST..BHE.D.2014.$jd 

done

Mas sempre vejo esse erro:

mv: cannot stat '2014.001.*.*.D890.E.m': No such file or directory
mv: cannot stat '2014.002.*.*.D890.E.m': No such file or directory
mv: cannot stat '2014.003.*.*.D890.E.m': No such file or directory
mv: cannot stat '2014.004.*.*.D890.E.m': No such file or directory
mv: cannot stat '2014.005.*.*.D890.E.m': No such file or directory
mv: cannot stat '2014.006.*.*.D890.E.m': No such file or directory
mv: cannot stat '2014.007.*.*.D890.E.m': No such file or directory
mv: cannot stat '2014.008.*.*.D890.E.m': No such file or directory
..
..
.. and so on!


Como posso conseguir isso funcionar?

    
por user3683346 20.02.2015 / 16:22

1 resposta

1

Script corrigido:

for file in /home/pintolcv/Downloads/2014*D890.E.m; do

filepath=${file%/*}
filebasename=${file##*/}

#echo "File equals: $file"
#echo "File path equals: $filepath"
#echo "File basename equals: $filebasename"

    if [[ -e "$file" ]]; then
        echo "File Found: $filebasename - ${filebasename:5:3}"
        mv "$file" "$filepath/IP.PMST.BHE..D.2014.${filebasename:5:3}"
    else
        echo "files do not exist"
    fi

done
    
por 20.02.2015 / 17:35

Tags