Site Tools


generic_linux_commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
generic_linux_commands [2026/03/25 13:02] admingeneric_linux_commands [2026/03/25 14:01] (current) admin
Line 38: Line 38:
   - Standard: s/^\(.*\), The \(.*\)$/The \1 \2/ — captures everything before , The  as \1 and everything after as \2, then prepends The   - Standard: s/^\(.*\), The \(.*\)$/The \1 \2/ — captures everything before , The  as \1 and everything after as \2, then prepends The
   - Combo pack: s/\(+ \)\(.*\), The \(.*\)/\1The \2 \3/ — moves The to before the subtitle within a +-delimited combo title   - Combo pack: s/\(+ \)\(.*\), The \(.*\)/\1The \2 \3/ — moves The to before the subtitle within a +-delimited combo title
 +
 +===== RENAME 'A', 'An' ROMS =====
 +Dry-run preview:
 +<code>
 +  find /mnt/DOCS1/ROMs/Library/roms -type f \( -name "*, A *" -o -name "*, An *" \) | sort | while IFS= read -r filepath; do
 +      dir=$(dirname "$filepath")
 +      filename=$(basename "$filepath")
 +      newname=$(echo "$filename" | sed 's/^\(.*\), \(An\{0,1\}\) \(.*\)$/\2 \1 \3/')
 +      echo "'$filename'"
 +      echo "  -> '$newname'"
 +  done
 +</code>
 +
 +Execute renames:
 +<code>
 +  find /mnt/DOCS1/ROMs/Library/roms -type f \( -name "*, A *" -o -name "*, An *" \) | sort | while IFS= read -r filepath; do
 +      dir=$(dirname "$filepath")
 +      filename=$(basename "$filepath")
 +      newname=$(echo "$filename" | sed 's/^\(.*\), \(An\{0,1\}\) \(.*\)$/\2 \1 \3/')
 +      if [ "$filename" != "$newname" ]; then
 +          mv -- "$filepath" "$dir/$newname"
 +          echo "Renamed: '$filename' -> '$newname'"
 +      fi
 +  done
 +</code>
 +
 +Key sed pattern:
 +  - s/^\(.*\), \(An\{0,1\}\) \(.*\)$/\2 \1 \3/ — \(An\{0,1\}\) matches either A or An, captures it as \2, then reconstructs as \2 \1 \3
  
  
generic_linux_commands.txt · Last modified: by admin · Currently locked by: 172.18.0.1