Skip to content

Instantly share code, notes, and snippets.

@wilspi
Created August 23, 2021 12:25
Show Gist options
  • Save wilspi/0d961bc34d3f9816a7d8249d1bbc9d79 to your computer and use it in GitHub Desktop.
Save wilspi/0d961bc34d3f9816a7d8249d1bbc9d79 to your computer and use it in GitHub Desktop.
Rename files by splitting by "-" and reversing the order in a directory
dir="$1"
for f in "$dir"/*; do
#filename="${cat '$f'}"
filename=${f:13:10} # string of length 10 from index 13
arrIN=(${filename//-/ }) # split by "-"
reversefilename="${arrIN[2]}-${arrIN[1]}-${arrIN[0]}"
reversef="journal/2021/${reversefilename}.md"
mv $f $reversef
#echo $reversefilename
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment