I have a directory of csv files with spaces and all kinds of characters. How do I rename them? The following gives an error.
#! /bin/bash
cd DirectoryName
for file in *.csv; do
#echo $file
filename=${file%.*}
file_clean=${filename//[ ()$+&\.\-\'\,]/_}
final= "$file_clean.csv"
mv "$file" $final
done
cd ..
Thanks!
UPDATE : (This works)
#! /bin/bash
cd DirectoryName
for file in *.csv; do
#echo $file
filename=${file%.*}
file_clean=${filename//[ ()$+&\.\-\'\,]/_}
final= "$file_clean.csv"
mv "$file" $final
done
cd ..