ASIC/FPGA Design and Verification Out Source Services
File rename in order to remove special characters like spaces and brackets.
- I find it always difficult, when I write a script, which needs to work on files, which contain special characters in its name.
- So here is a nice way to remove spaces and some other characters as well. The script can be easily extended to trim other characters too if needed.
- If just file re name is required, there is a linux command rename , which will usually be good enough. On old linux or cygwin, the rename command is, sometimes, not available.
- So this page gives a nice start for such a script and shows an example for the rename command usage.
#!/bin/bash
for f in '../../movie/To/kuku - The Best Collection 2CD/kuku - The Best Collection CD 2'/*.mp3; do
#tr A-Z a-z
file1=$(echo $f | tr ' ' _ | tr \' _ | tr \( _ | tr \) _)
file2=`echo $file1 | sed "s/\.\.\///g"`
file3=`echo $file2 | sed "s/_//g"`
file4=`echo $file3 | sed "s/-//g"`
file5=`echo $file4 | sed "s/.*\([0-9][0-9].*\.mp3\)/\1/g"`
fileZ="D2_"$file5
#echo $f
#echo $fileZ
#echo " "
[ ! -f $fileZ ] && mv -f "$f" $fileZ
#[ ! -f $fileZ ] && ln -s "$f" $fileZ
#[ ! -f $fileZ ] && cp "$f" $fileZ
done
Example for rename usage: rename 's/[ _]//g' *.mp3
Contact me now at: |