Posted By

jlmarks on 03/11/15


Tagged

Bash String loops substring looping stringReplacement


Versions (?)

bash rename all files which meet pattern


 / Published in: Bash
 

Just a basic bash snippet, of interest is the substring replacement, imo.

  1. #!/usr/bin/env bash
  2.  
  3.  
  4. for file in .* *; do
  5. # skip current/previous dirs and unresolved wildcards
  6. if [[ "$file"=="grimm*" ]]
  7. then
  8. old="grimm.3"
  9. new="Grimm.S03E"
  10. newname=${file/grimm.3/Grimm.S03E}
  11. mv "$file" ./$newname
  12. # ${string/substring/replacement}
  13. fi
  14. done

Report this snippet  

You need to login to post a comment.