From 67ed4869eaaf47c63c7b74f457beb0ffdea30944 Mon Sep 17 00:00:00 2001 From: sickprodigy Date: Wed, 22 Oct 2025 19:45:41 -0400 Subject: [PATCH] move/find id to end of filename. In my situation it was between second and third " - " So splits apart and put back together. --- move-find-id-to-end-filename.bash | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 move-find-id-to-end-filename.bash diff --git a/move-find-id-to-end-filename.bash b/move-find-id-to-end-filename.bash new file mode 100644 index 0000000..c6ad7e7 --- /dev/null +++ b/move-find-id-to-end-filename.bash @@ -0,0 +1,26 @@ +#!/bin/bash +shopt -s nullglob + +for f in *.mp4 *.mkv *.mov *.avi; do + [ -f "$f" ] || continue + + base="${f%.*}" + ext="${f##*.}" + + # Match: date - number - id - rest + # Example: 20140720 - 097 - oaHzqMgnI70 - TempleOS - God for Larry Page 7_20 K + if [[ "$base" =~ ^([^[:space:]]+)[[:space:]]*-[[:space:]]*([^[:space:]]+)[[:space:]]*-[[:space:]]*([A-Za-z0-9_-]+)[[:space:]]*-[[:space:]]*(.*)$ ]]; then + datepart="${BASH_REMATCH[1]}" + numpart="${BASH_REMATCH[2]}" + id="${BASH_REMATCH[3]}" + rest="${BASH_REMATCH[4]}" + + newname="${datepart} - ${numpart} - ${rest} [${id}].${ext}" + + echo "Would rename: $f → $newname" + # Comment next line to test without renaming + mv -i -- "$f" "$newname" + else + echo "Skipping (pattern mismatch): $f" + fi +done