Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

File rename in order to remove special characters like spaces and brackets.

  1. I find it always difficult, when I write a script, which needs to work on files, which contain special characters in its name.

  2. 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.

  3. 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.

  4. So this page gives a nice start for such a script and shows an example for the rename command usage.


  5. #!/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:

  ...


I would be happy to offer my services. Call ASAP !


Home

Download Area






Search This Site


Feedback This Site




new pages on this site