PDA

Visualizza la versione completa : [bash] eliminare determinate stringhe dal nome del file


Rommel
12-02-2005, 16:03
salve a tutti,
dovrei rinominare alcuni file che contengono la stringa "divx" nel nome del file.
qualcuno conosce/sa fare uno script che levi divx? (n.b. case unsensitive)

cacao74
12-02-2005, 17:15
[sergio@winnie ~/tmp/test]$ for i in `seq 0 9`; do touch mydivxfile-0$i.mpg; done
[sergio@winnie ~/tmp/test]$ for i in `seq 10 19`; do touch myDIVXfile-$i.mpg; done
[sergio@winnie ~/tmp/test]$ for i in `seq 20 29`; do touch myDIVXfile-0$i.mpg; done
[sergio@winnie ~/tmp/test]$ ls
myDIVXfile-020.mpg myDIVXfile-026.mpg myDIVXfile-12.mpg myDIVXfile-18.mpg mydivxfile-04.mpg
myDIVXfile-021.mpg myDIVXfile-027.mpg myDIVXfile-13.mpg myDIVXfile-19.mpg mydivxfile-05.mpg
myDIVXfile-022.mpg myDIVXfile-028.mpg myDIVXfile-14.mpg mydivxfile-00.mpg mydivxfile-06.mpg
myDIVXfile-023.mpg myDIVXfile-029.mpg myDIVXfile-15.mpg mydivxfile-01.mpg mydivxfile-07.mpg
myDIVXfile-024.mpg myDIVXfile-10.mpg myDIVXfile-16.mpg mydivxfile-02.mpg mydivxfile-08.mpg
myDIVXfile-025.mpg myDIVXfile-11.mpg myDIVXfile-17.mpg mydivxfile-03.mpg mydivxfile-09.mpg
[sergio@winnie ~/tmp/test]$ for file in ./*; do mv $file ${file%%[dD][iI][vV][xX]*}${file##*[dD][iI][vV][xX]}; done
[sergio@winnie ~/tmp/test]$ ls
myfile-00.mpg myfile-022.mpg myfile-027.mpg myfile-05.mpg myfile-10.mpg myfile-15.mpg
myfile-01.mpg myfile-023.mpg myfile-028.mpg myfile-06.mpg myfile-11.mpg myfile-16.mpg
myfile-02.mpg myfile-024.mpg myfile-029.mpg myfile-07.mpg myfile-12.mpg myfile-17.mpg
myfile-020.mpg myfile-025.mpg myfile-03.mpg myfile-08.mpg myfile-13.mpg myfile-18.mpg
myfile-021.mpg myfile-026.mpg myfile-04.mpg myfile-09.mpg myfile-14.mpg myfile-19.mpg
[sergio@winnie ~/tmp/test]$


ciao

Ikitt
12-02-2005, 17:30
Originariamente inviato da cacao74


[sergio@winnie ~/tmp/test]$ for file in ./*; do mv $file ${file%%[dD][iI][vV][xX]*}${file##*[dD][iI][vV][xX]}; done


Fortissimo! E` tempo che mi aggiorni a bash >= 2.x, decisamente :fagiano:

Rommel
13-02-2005, 00:06
funziona!
grazie e complimenti per la bravura :ciauz:

Loading