Skip to content

Instantly share code, notes, and snippets.

@gyakkun
Last active March 7, 2022 01:05
Show Gist options
  • Select an option

  • Save gyakkun/931ab91290fcf58211694b7b9a90d6b3 to your computer and use it in GitHub Desktop.

Select an option

Save gyakkun/931ab91290fcf58211694b7b9a90d6b3 to your computer and use it in GitHub Desktop.
Rename U2 torrent in Git Bash (Windows)
#!/bin/bash
OLDIFS="$IFS"
IFS=$'\n'
PATH='/c/Program Files/Transmission':$PATH
for i in $(ls \[U2\].*.torrent); do
torrent_name=$(transmission-show $i | grep -Po "(?<=^Name: ).+$")
echo "Torrent name: $torrent_name"
torrent_id=$(echo $i | grep -Po "(?<=\.)\d+(?=\.torrent)")
echo "Torrent ID: $torrent_id"
new_name="[U2].$torrent_name.$torrent_id.torrent"
echo "Original name: $i"
echo "New name: $new_name"
mv "$i" "$new_name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment