Remove special character ($) from file names

Hello

I've searched here and on the 'net for examples of a script or command line function that will remove the $ character from all file names only that can be done within the directory that contains the file names - which are all html files.

ie, I have a directory that contains html files and some of those have file names containing the $ character which I would like to have removed. As there is in excess of 1000 files in the directory, it's not a process I'd want to do manually!

Any help appreciated!

 
perl -le 'foreach(@ARGV){$a=$_; $_=~s/\$//g; `mv $a $_`}' *

Thank you, seems there are issues with the suggestion as output errors.

Eg:

For file name without a $ in the file name:

mv: `in-1-of-10-american-teen-dvd.html' and `in-1-of-10-american-teen-dvd.html' are the same file

and for file name containing a $ in the file name:

mv: cannot stat `in-0-000-to-style-your-home.html': No such file or directory

The above file name is actually in-$10-000-to-style-your-home.html so it also appears to be dropping the 1 following the $

Or try..

!#/bin/ksh
for file in `ls -1 *\$*` # Note ls -1(one) and not the alphabet L
do
    NEW_FILE=$(echo "$file" | sed 's/\$//g')
    mv "$file" "$NEW_FILE"
    echo "Moved file: $file"
done
1 Like

Oops!!..
This should work.

 
perl -le 'foreach(@ARGV){if($_ =~/\$/){$a =$_; $a=~s/\$/\\\$/g;$_=~s/\$//g; print `mv $a $_`}}' *
1 Like

Thank you ! Worked 100% !

My pleasure :slight_smile: