1

Suppose I have a list of words in a text file e.g:

abstinence ; abuse ; academic ; accommodate ; accommodation ; accommodationist ; accomplice ; accomplish ; accord ; account ; accountable ; acquiescence ; acrimonious ; acronym

I want to change each word to a URL and download the file using commands in a terminal window. For example the first word from the list, that is, abstinence will change into https://ssl.gstatic.com/dictionary/static/sounds/de/0/abstinence.mp3 and the file abstinence.mp3 will be downloaded into a folder. Then the next word, that is, abuse will change into the url https://ssl.gstatic.com/dictionary/static/sounds/de/0/abuse.mp3 and the file abuse.mp3 will be downloaded from the url and so on.

Can it be done using commad line in terminal or using a script run in command line?

2

Easily:

while read -d ';' word; do 
    wget "https://ssl.gstatic.com/dictionary/static/sounds/de/0/$word.mp3"; 
done < file

Explanation

while read -d';' word will read each line from file, and save each ;-separated word (because of -d';') as $word. This is then passed to wget which downloads the file.

2

This works for me:

for word in $(tr -d \; < wordlist.txt); do
   wget https://ssl.gstatic.com/dictionary/static/sounds/de/0/$word.mp3
done
1

On BSD/OS X

sed -i '' 's/;/\
/g' mp3.txt && sed -i '' s'/^/wget\ https:\/\/ssl.gstatic.com\/dictionary\/static\/sounds\/de\/0\//g' mp3.txt && sed -i '' s'/$/.mp3/g' mp3.txt && chmod +x mp3.txt && ./mp3.txt

using sed.

0

To download a list of files, you can use wget -i file, where file is the name of a file with a list of URL(s) to download.

For more details you can review the help page: man wget.

Constructing such a list of URLs from your list of words is easily done with text processing tools like sed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.