Script to rename files, removing common name feature
We had a bit of a screwup at work last week (yes, I'll take the blame!) where a large number of files and directories were deleted from dropbox. There was no back up (except my own files, because I ALWAYS backup MY data, sorry, it's been a rough week :( ).
Anyway as it turns out the files weren't completely deleted, they survived in .dropbox.cache but all have been renamed. An example is like this: Code:
Ashley Barnes (deleted 4fa2da8b-69620-cc228a29).pdf Help is much appreciated. |
Like this ?
Code:
echo "Ashley Barnes (deleted 4fa2da8b-69620-cc228a29).pdf"|sed s/\ \(.*\)// eg Code:
echo 'Ashley Barnes.pdf'| sed s/\ /_/ |
Yes that's the type of output I'm seeking. How would I go about scripting that to rename about 2000 files. The only common feature to all the files is " (deleted XXXXXX)."?
|
Code:
# before Useful links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
Quote:
THANK YOU! Yes that helps. I had to change *.pdf to *deleted*, but I almost feel rude even saying that! Works perfect and might get me out of the doghouse a bit! Well it works perfectly anyway, the doghouse is a different issue! |
No need to use sed in the above. The shell's built-in parameter substitution will be faster and more efficient.
Code:
file='Ashley Barnes (deleted 4fa2da8b-69620-cc228a29).pdf' BTW, your system probably has some form of batch renamer available to you already, or at least easily installed. |
All times are GMT -5. The time now is 02:45 AM. |