Search code examples
bashbatch-rename

BASH - Removing everything before a specified character (script to run on Windows)


I have a lot of files in a folder with the following format:

Node0123_RL2581_GS2001.jpg

I want to remove everything before the "RL" so it will be:

RL2581_GS2001.jpg

Note that the number of characters before the "RL" varies between 8 and 9 characters.

Thank you for any advice! :)


Solution

  • bash solution:

    for f in *_RL*.jpg; do mv "$f" "RL${f#*_RL}"; done
    

    • ${f#*_RL} - truncate the left part of the string(filename) till encountering _RL (including)