[solved]removing characters from a mass of file names


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [solved]removing characters from a mass of file names
# 1  
Old 10-25-2012
[solved]removing characters from a mass of file names

I found a closed thread that helped quite a bit. I tried adding the URL, but I can't because I don't have enough points... ?


Modifying the syntax to remove [ ] ! ~

Code:
find . -type f -name '*[\[\]~\!]*' |
   while IFS= read -r; do
     mv -- "$REPLY" "${REPLY//[\[\]~\!]}";
   done

These messages are presented and nothing gets renamed:
Quote:
mv: rename ./One Piece 423 Hd ,720p.mp4 ~bY TzaTziki ~ [non!english!subs] - 8517336 bytes - [TzaTziki] One 423/[TzaTziki]_One_Piece_423_HD.sfv to ./One Piece 423 Hd ,720p.mp4 bY TzaTziki nonenglishsubs - 8517336 bytes - TzaTziki One 423/TzaTziki_One_Piece_423_HD.sfv: No such file or directory
I thinking it's because it's mv'ing the file in the directory with what would be the new directory name BEFORE the directory was renamed. In the end, I need to rename the directories AND the files within.

Thanks!!

---------- Post updated at 10:25 PM ---------- Previous update was at 10:12 PM ----------

Go ahead and close this thread. Found another thread and came up with this:

Code:
find . -depth -name "*[\[\]\~\!]*" |     # Find all files or folders containing 'bad' characters.
while read FILEDIR                            # Read them line-by-line.
do
        DIR="${FILEDIR%/*}"                   # Get the folder its inside
        FILE="${FILEDIR/*\/}"                 # Get the plain name.
        NEWFILE="${FILE//[\[\]\~\!]/_}" # Substitute _ for bad things.
        mv "$DIR/$FILE" "$DIR/$NEWFILE"  # Rename it.
done

This User Gave Thanks to rabidphilbrick For This Post:
# 2  
Old 10-25-2012
Thanks for posting your solution.
# 3  
Old 10-25-2012
special character u'\u014d'

So, the whole point of coming up with this is because a processing script is returning:

Quote:
Traceback (most recent call last):
File "cherrypy/_cprequest.pyc", line 660, in respond
File "cherrypy/lib/encoding.pyc", line 193, in __call__
File "cherrypy/_cpdispatch.pyc", line 25, in __call__
File "/Applications/SickBeard.app/Contents/Resources/sickbeard/webserve.py", line 1650, in processEpisode
File "/Applications/SickBeard.app/Contents/Resources/sickbeard/processTV.py", line 93, in processDir
File "/Applications/SickBeard.app/Contents/Resources/sickbeard/processTV.py", line 104, in processDir
File "/Applications/SickBeard.app/Contents/Resources/sickbeard/postProcessor.py", line 788, in process
File "/Applications/SickBeard.app/Contents/Resources/sickbeard/postProcessor.py", line 261, in _move
File "/Applications/SickBeard.app/Contents/Resources/sickbeard/postProcessor.py", line 239, in _combined_file_operation
File "/Applications/SickBeard.app/Contents/Resources/sickbeard/encodingKludge.py", line 56, in ek
File "encodings/mac_roman.pyc", line 12, in encode
UnicodeEncodeError: 'charmap' codec can't encode character u'\u014d' in position 31: character maps to <undefined>

I found a thread on their support site that brackets botch the script. So, the above solution remove the brackets and other characters. It's started happening again and I think there more to this:

Quote:
u'\u014d'

I found this:
ht tp://www.fileformat.info/info/unicode/char/14d/index.htm

But how can I implement that special character into the removal script?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to remove first few characters from multiple file names without do loop?

Hi Fellows, I was wondering how I can remove first few characters from multiple file names without do loop in unix? e.g. water123.xyz water456.xyz to 123.xyz 456.xyz Thanks Paul Thanks. (3 Replies)
Discussion started by: Paul Moghadam
3 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Removing control-m characters from shell script

Hi All, I need to remove control m character from a file. Steps which i am doing in shell script are: 1) We are comparing the header of the file to the database table header Here the file header has control-m characters. How do i remove it. Please help. Below are the steps i am using,... (12 Replies)
Discussion started by: abhi_123
12 Replies

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

4. Shell Programming and Scripting

Removing unknow chars from file names.

I'm trying to move a large folder to an external drive but some files have these weird chars that the external drive won't accept. Does anyone know any command of any bash script that will look through a given folder and remove any weird chars? (4 Replies)
Discussion started by: Joktaa
4 Replies

5. UNIX for Dummies Questions & Answers

Removing path name from list of file names

I have this piece of code printf '%s\n' $pth*.msf | tr ' ' '\n' | sort -t '-' -k7 -k6r \ | awk -F- '{c=($6$7!=p&&FNR!=1)?ORS:"";p=$6$7}{printf("%c%s\n",c,$0)}' When I run it I get /home/chrisd/tatsh/branches/terr0.50/darwin/n02-z30-dsr65-terr0.50-dc0.002-8x6drw-csq.msf... (8 Replies)
Discussion started by: kristinu
8 Replies

6. Shell Programming and Scripting

[SOLVED] Changing file names

I have written a csh script that changes the name of file from src to dst. I am getting the error below: TESTAmvfiles DONE TESTAmvfiles set: Variable name must begin with a letter. The csh script is: #!/bin/csh #... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

Removing files with same text but different file names

Hi All, I have some 50,000 HTML files in a directory. The problem is; some HTML files are duplicate versions that is wget crawled them two times and gave them file names by appending 1, 2, 3 etc after each crawl. For example, if the file index.html has been crawled several times, it has been... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

8. UNIX for Dummies Questions & Answers

removing first 7 characters of directory names

Hi, I'm relatively new to unix, and would like to change the following files in a particular directory. The files have names like: M10_90_Phcn402_3F.ab1 M10_94_Sput402_3F.ab1 M11_92_Abrg402_3R.ab1 M10_91_Cdel402_3F.ab1 M11_90_Phcn402_3R.ab1 M12_84_Sput402_3R.ab1... (4 Replies)
Discussion started by: euspilapteryx
4 Replies

9. Shell Programming and Scripting

Weird Ascii characters in file names

Hi. I have files in my OS that has weird file names with not-conventional ascii characters. I would like to run them but I can't refer them. I know the ascii # of the problematic characters. I can't change their name since it belongs to a 3rd party program... but I want to run it. is there... (2 Replies)
Discussion started by: yamsin789
2 Replies

10. Shell Programming and Scripting

Replace characters in all file names in a particular directory

Hi, I have searched the forum on how to mass replace the file names. We are doing the migration and I am trying to accomplish a task where I have to replace all UNIX scripts in a particular directory that start with bdw to fdm... For example: bdw0110137.sh should be fdm0110137.sh Keep the... (4 Replies)
Discussion started by: madhunk
4 Replies
Login or Register to Ask a Question