Remove special character ($) from file names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove special character ($) from file names
# 1  
Old 06-02-2011
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!
# 2  
Old 06-02-2011
Code:
 
perl -le 'foreach(@ARGV){$a=$_; $_=~s/\$//g; `mv $a $_`}' *


Last edited by getmmg; 06-02-2011 at 09:54 AM.. Reason: Added Code tags
# 3  
Old 06-02-2011
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 $
# 4  
Old 06-02-2011
Or try..
Code:
!#/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

This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 06-02-2011
Quote:
Originally Posted by competitions
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 $

Oops!!..
This should work.

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

This User Gave Thanks to getmmg For This Post:
# 6  
Old 06-03-2011
Thank you ! Worked 100% !
# 7  
Old 06-03-2011
Quote:
Originally Posted by competitions
Thank you ! Worked 100% !
My pleasure Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove a word that ends with special character "!"

Hi all. I want to use sed to remove a word that ends with "!" in the first page of a file. The word I want to remove is: "DNA!". I have search for an answer and nothing of what I found helped me. ~faizlo (2 Replies)
Discussion started by: faizlo
2 Replies

2. Shell Programming and Scripting

Remove word after special character "/"

Hi There, I have one requirement to remove word after character "/". Input file is 2017-07-12|02|user1l|domain1/userl|0 2017-07-12|02|user2|domain1/user2|5 2017-07-12|02|user3|domain2/user3|0 2017-07-12|02|user4|domain1/user4|432 and require OP file is ... (2 Replies)
Discussion started by: anshu ranjan
2 Replies

3. Shell Programming and Scripting

Remove blank space and insert special character

Hi Folks, I have a huge data of the below format abc #apple 1200 06/23 ghj #orange 1500 06/27 uyt #banana 2300 05/13 efg #vegetable 0700 04/16 After first 3 letters, i have 9 spaces and after fruit there are no specific fixed space, but it varies... (4 Replies)
Discussion started by: jayadanabalan
4 Replies

4. Shell Programming and Scripting

Remove some special ascii character

Hello I have this special caracter after retreving rows from sql server: "....spasses: • Entrem al valort 6050108002811 • El donem..." I would like a sed command to remove it..or just know it's ascii code in order to replace it into my sql sentence.. Hope some one knows how to do that.... (7 Replies)
Discussion started by: ldiaz2106
7 Replies

5. Tips and Tutorials

How to manage file names with special characters

One of the common questions asked are: how do i remove/move/rename files with special (non-printable) characters in their name? "Special" doesn't always mean the same. As there are more and less special characters, some solutions are presented, ranging from simple to very complicated. Usually a... (0 Replies)
Discussion started by: bakunin
0 Replies

6. Shell Programming and Scripting

remove special character from a specific column

Hello , i have a text file like this : A123 c12AB c32DD aaaa B123 23DS 12QW bbbb C123 2GR 3RG cccccc i want to remove the numbers from second and third column only. i tried this : perl -pe 's///g' file.txt > newfile.txt but it will remove the number from... (7 Replies)
Discussion started by: shelladdict
7 Replies

7. Shell Programming and Scripting

remove special character from a textfile

Can any one plse help me writing shell script to removing some special character pattern (like / > -------, / > / > ------- etc....as shown below) from the text file ASAP. / > ------- <tag-normalization tag-name="EXECSERVPRODUCT" read-only="false" part="body"> ... (3 Replies)
Discussion started by: bkc
3 Replies

8. Shell Programming and Scripting

Remove box like special character from end of string

Hi All, How to remove a box like special character which appears at the end of a string/line/record. I have no clue what this box like special character is. It is transparent square like box. This appears in a .DAT file at the end of header. I'm to compare a value in header with a parameter.... (16 Replies)
Discussion started by: Qwerty123
16 Replies

9. UNIX for Dummies Questions & Answers

Special character in my file

I have a special character in my file. It displays as a '#' sign but when I do this command I do not find the line. fgrep 'G#ant' file1 I want to replace the special character with another value but I need to know what character it really is. Any ideas on how to replace this '#' value with... (3 Replies)
Discussion started by: Ryan2786
3 Replies
Login or Register to Ask a Question