oliverhentairules

Another coding question ^^

Sep 5th, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Hmm, yet another question for the coders, please ? ^_^
  2.  
  3. My "previously current" renaming shell relied on this line, which was annoyingly making committing mistakes SUPER easy, for instance :
  4. mv $file ${file%.zip_\(English\).zip}_.zip
  5. Using that script led me to making minor mistakes, there were occasional strings combos that I hadn't imagined breaking everything... You can picture the loss of time - I blame nobody but me, of course.
  6. And then I found this PERFECTLY SIMPLE replacement script, with the replacement arguments in the command line :
  7. (source : http://superuser.com/questions/508731/find-and-replace-string-in-filenames )
  8. It even allows single quotes, no more escaping or white spaces hell ! YAY.
  9.  
  10. #!/bin/bash
  11. (( $# != 2 )) && exit 1
  12. for f in *.zip; do
  13. newf="${f//$1/$2}"
  14. if [[ $f != $newf ]]; then
  15. mv "$f" "$newf"
  16. fi
  17. done
  18.  
  19. Running it :
  20. ./replacestr 'original text' 'new text'
  21.  
  22.  
  23. Now, I wanted to combine it with my idea, a .txt file containing the list of the only files that I want to rename.
  24. After all, it worked with the previous script :
  25.  
  26. #!/bin/bash
  27. for file in *.zip
  28. do
  29. mv $file ${file%_\(English\).zip}__\(English\).zip
  30. done
  31.  
  32. Running it :
  33. cat fixzips-list.txt | xargs ./rename
  34.  
  35. I wanted to do an adaptation of the same with the new renaming script :
  36.  
  37. cat fixzips-list.txt | xargs ./replacestr '(www.hentai' '(www.TROLOLOL'
  38. ... except that, this time, it didn't work, the renaming wasn't done.
  39.  
  40. Please, do you see what kind of option I might have missed ?
  41. I don't think a {} should be added here, but, I might be mistaken... Ah well, I don't know ^^
  42. Thanks if you can help ! :)
Add Comment
Please, Sign In to add comment