Skip to content

Instantly share code, notes, and snippets.

@meysam81
Created December 9, 2018 16:48
Show Gist options
  • Save meysam81/f2d9062f54500905a7d691cd49d5a06f to your computer and use it in GitHub Desktop.
Save meysam81/f2d9062f54500905a7d691cd49d5a06f to your computer and use it in GitHub Desktop.
a bash script to gather p30download.com links to for download
#!/bin/bash
if [[ "$#" -ne 2 ]]; then
echo "usage pdlist <filename> <number_of_parts>"
exit 1
fi
parts="$2"
filename="$1"
partnum=$(echo ${filename##*part})
partnum=$(echo ${partnum%%.*})
partnum=$(echo ${#partnum})
for ((i = 1; i <= $parts; i++)); do
if [[ $partnum -eq 2 ]]; then
filenum=$([[ $i -gt 9 ]] && echo "$i" || echo "0$i")
elif [[ $partnum -eq 1 ]]; then
filenum="$i"
fi
newfilenum=$(echo $filename | sed "s|part[0-9]*|part$filenum|")
echo $newfilenum
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment