MUNG

mashuntilnogoodmashuntilnogoodmashuntilnogoodmashuntilnogoodmashuntilnogoodmashuntilnogoodmashuntilnogood

Monday, December 12, 2005

Rename file script.

This might come in handy for some of you Unix/Linux people out there. It adds a string to the name of a file before the file extension. Great for renaming tons of files in a similar manner. There is probably a better way to do it but this works well for me.

echo "Enter Name Addition: "
read newadd

for file in *
do
filename=`echo $file | awk 'BEGIN {RS="."} {print $0}'`
filename2=`echo $filename | awk '{print $1}'`
newname=`echo $file | sed -e 's/'"$filename2"'/'"$filename2-$newadd"'/g'`
mv $file $newname
done

2 Comments:

  • At 6:28 PM, Blogger Guicho said…

    Now If I could only figure out how to do this in the terminal ..

     
  • At 6:46 PM, Blogger Joe Williams said…

    just create a file like name.sh in vi, nano or whatever(doesnt even need an extension) paste the script in it. then run: chmod +x name.sh to make it executable. then run it: ./name.sh

    thats it!

     

Post a Comment

<< Home