Skip to content

Instantly share code, notes, and snippets.

@olekscode
Last active October 13, 2018 10:53
Show Gist options
  • Save olekscode/ce0f30807ee9068470976dd1fd521ee1 to your computer and use it in GitHub Desktop.
Save olekscode/ce0f30807ee9068470976dd1fd521ee1 to your computer and use it in GitHub Desktop.
Find and replace substring in the names of multiple files
# Replaces EN with UK in the names of all *.srt files in the current working directory.
# Assumes that there is only one EN in each name.
#
# IDEA
# -------------
# For all *.srt files that have EN somewhere in their name ($x)
# Store everything before EN as $prefix
# Store everything after EN as $suffix
# Rename each file $x with $prefix + UK + $suffix
#
# EXAMPLE
# -------------
# C019-Videos-ProfStef-EN-V2-HD_720p_4Mbs-3.srt
# C019-W1S-Videos-ColoringExpression-EN-CM-v3-HD_720p_4Mbs-2.srt
# ...
# C019-Videos-ProfStef-UK-V2-HD_720p_4Mbs-3.srt
# C019-W1S-Videos-ColoringExpression-UK-CM-v3-HD_720p_4Mbs-2.srt
for x in *EN*.srt;
do
prefix=${x%EN*};
suffix=${x#*EN};
mv $x $prefix\UK$suffix;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment