Reputation: 56
I have a file music.txt with audios to download, looking like this:
http://somehow/music/hexfilename1.mp3 1.mp3
http://somehow/music/hexfilename2.mp3 2.mp3
http://somehow/music/hexfilename3.mp3 3.mp3
http://somehow/music/hexfilename4.mp3 4.mp3
I just want to download the mp3 files, and save as specified names. For instance, download from http://somehow/music/hexfilename1.mp3, we will save as 1.mp3.
Upvotes: 0
Views: 3066
Reputation: 517
Actually, this is an easy work, but there may be 2 situations:
If your music.txt
is like that in your answer, with url being the first group, and output file being the second, then you can use the following command:
IFS="\n"
for line in $(cat music.txt)
do
url=$(echo $line | awk '{ print $1 }')
out=$(echo $line | awk '{ print $2 }')
wget "$url" -O "$out"
done
For the other situation, you just don't need that much script and simply use a for
loop to go thru each line and pass the parameters to wget
.
Hope this helps.
Upvotes: 3
Reputation:
You can read
them into variables using a while
loop with read
:
while read a b; do wget -O "$b" "$a"; done < music.txt
Upvotes: 5