Results 1 to 8 of 8
Hi Friends,
I have many pdf files which contain "%" sign also in the name. I want to rename that all files by replacing "%" to "-" Its hierarchy of ...
- 06-21-2011 #1Just Joined!
- Join Date
- Apr 2011
- Posts
- 22
Renaming Multiple Files
Hi Friends,
I have many pdf files which contain "%" sign also in the name. I want to rename that all files by replacing "%" to "-" Its hierarchy of many files and folders. Is there any solution to do this at one time? OR any script for this?
Thanks & Regards
Parag Nehete
- 06-21-2011 #2Replace <PDF_DIRECTORY> with the actual pathCode:
find <PDF_DIRECTORY> -type f -print0 | while read -r -d '' SOURCE ; do DIRECTORY=$(dirname ${SOURCE}); FILENAME=$(basename ${SOURCE}|sed s/%/-/g);echo "OLD : ${SOURCE} -- NEW : ${DIRECTORY}/${FILENAME}"; done
If the output looks good, then replace the echo with a mv, and of course get rid of the text partLast edited by Irithori; 06-21-2011 at 09:31 AM.
You must always face the curtain with a bow.
- 06-21-2011 #3Just Joined!
- Join Date
- Apr 2011
- Posts
- 22
Works
Thank you very much sir......
- 06-21-2011 #4
yw.
I just noticed, I missed to filter the files more closely via an additional argument to find: -iname "*.pdf"
But seems to be ok already
You must always face the curtain with a bow.
- 06-21-2011 #5Just Joined!
- Join Date
- Apr 2011
- Posts
- 22
- 06-21-2011 #6
Yep.
First test, then go live.
Need to remind my management of that principle every day
The oneliner was written to be non-destructive, so it just outputs what the names would look like.
That´s why I have written:
If the output looks good, then replace the echo with a mv, and of course get rid of the text partYou must always face the curtain with a bow.
- 06-23-2011 #7Just Joined!
- Join Date
- Apr 2011
- Posts
- 22
Yes sir it works......but now i have another problem. Some files contain ' sign also. How can i rename that also by replacing ' to -
- 06-23-2011 #8
With almost the same line.
Modify the sed part accordingly, and protect the ' from being interpreted by the shell by encapsulating the expression in "
You can also extend it to match multiple chars to be replaced with - by using the OR operator and a group.You must always face the curtain with a bow.


Reply With Quote
