Created
November 4, 2023 21:36
-
-
Save azimut/418d2ae6db31406b400228c12fc29c7f to your computer and use it in GitHub Desktop.
rename files based on the filenames on a txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
cd '/home/user/work/videos' | |
readarray -t lines <'./filenames.txt' | |
rtrim() { sed -e 's/[[:space:]]*$//'; } | |
sanitize() { tr -cd '[:alnum:] .'; } # fat32 support | |
for ((i = 1; i <= ${#lines[@]}; i++)); do | |
newfilename="$(printf '%03d.%s\n' "$i" "${lines[i - 1]}" | rtrim | sanitize)" | |
sudo mv ${i}.mp4 "${newfilename}.mp4" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment