bulk transformation of filenames
Hi all
RHEL 4 I have a folder in which there are hundreds of files that have been created with %20 in them. Is there any way of doing a bulk transformation on those names to replace them with spaces or underscores? Thanks. |
find . -type f >list
for f in `cat list` do fname=`echo $f | sed s/%20/\ /g` mv $f "$fname" done Warning: Backup the data before doing this ... |
Thanks - will try it out now (with backup of course ;-)
|
Unfortunately I just get the following error
mv: cannot move `jeff%20file%20test.txt' to `echo $f | sed -e s/%20/\\ /g': No such file or directory (the double backslash at %20/\\ only appears in this output it is not in the original command) it thinks the sed command is the destination string - perhaps it needs an exec??? |
Really strange. You can try with exec - or better eval. Or you can do a simple string replacement like this
Code:
mv $file "${file//\%20/ }" |
I think you used the wrong character in the line reading
Code:
fname=`echo $f | sed s/%20/\ /g` Code:
fname=$(echo $f | sed s/%20/\ /g) |
AND THE WINNER IS! (fanfare)
Quote:
Works like a dream. Thanks to everyone who took the time to help me. Thanks to Blacky for pointing out the possible confusion between us and uk keyboard layouts. Jeff. |
Tried to do something like this, and going by the contributions made in this thread, got the following done:
Code:
ls -l | awk {'print $9'} | grep '%20' > list Works like a charm, also will display whatever it's renamed. So even though I wasn't the one that asked this question, thanks for the codes :) |
Just to reinforce colucix' comment, do replace with underscores, not spaces, as many Unix cmds/tools do not behave well with spaces in filenames (default design is that args to cmds are space separated ...)
|
All times are GMT -5. The time now is 08:01 AM. |