#!/bin/bash FILE=$@ LINES=$(cat $FILE) counter=1 for line in $LINES; do youtube-dl -x --audio-format mp3 "https://www.youtube.com/watch?v=$line" || echo "$line" >> "$FILE""_failed" counter=$((counter+1)) tail -n "+$counter" "$FILE" > "$FILE""_remaining" done rm "$FILE""_remaining"