Tuesday, June 29, 2010

bash string processing and file renaming

For some reason, some 200 files had not been renamed on the dreamhost download server. Occasional reader emails of files not found alerted me to this.

When I checked the rename shell script, these files were not listed in it. They did have download filenames in our local database, but were not listed in the rename shell script for some reason. Manually renamed them by doing some string manipulation:
find ~ -name '* *' sort > toberenamed.txt
cat toberenamed.txt while read FILE ;

do echo mv \"$FILE\" $(echo $FILEsed 's/ /_/g') ;
done > toberenamed.sh
vim toberenamed.sh

#(to check manually and remove non-essentials)
chmod +x toberenamed.sh
./toberenamed.sh

No comments:

Post a Comment