Execute isto na pasta dos seus arquivos:
find . -type f -name "Example_30*.DAT" | awk -F\_ '{printf "cp -v %s Ex_Example_%s.DAT\n", $0, $3}' | bash
-
find . -type f
: pesquisa apenas por arquivos -
-name "Example_30*.DAT"
: arquivo começando com "Example_30" e terminando com ".DAT" -
| awk -F\_
: canalize isso paraawk
e defina o delimitador para_
-
'{printf "cp -v %s Ex_Example_%s.DAT\n", $0, $3}'
: gere um comando assim:cp -v oldname newname
-
| bash
: e canalize isso parabash
para executá-lo
A saída deve ficar assim:
»./Example_30_002_20130913180854.DAT“ -> »Ex_Example_002.DAT“
»./Example_30_005_20130913180904.DAT“ -> »Ex_Example_005.DAT“
»./Example_30_003_20130913180857.DAT“ -> »Ex_Example_003.DAT“
»./Example_30_006_20130913180907.DAT“ -> »Ex_Example_006.DAT“
»./Example_30_007_20130913180911.DAT“ -> »Ex_Example_007.DAT“
»./Example_30_004_20130913180901.DAT“ -> »Ex_Example_004.DAT“
»./Example_30_001_20130913175000.DAT“ -> »Ex_Example_001.DAT“
Editar:
What if I want it to be put in a script outside of that folder? How would I go about doing it?
Crie um arquivo chamado script
. Adicione as seguintes linhas ao arquivo:
#!/bin/bash
DIRECTORY=/path/to/dir/
cd $DIRECTORY
find . -type f -name "Example_30*.DAT" | awk -F\_ '{printf "cp -v %s Ex_Example_%s.DAT\n", $0, $3}' | bash
cd -
Torne o script executável:
chmod u+x script
Depois, chame o script:
./script
ou
/absolute/path/to/script