2

So I have a .sh script that needs to wget a lot of files. I have a text file set up like this

http://www.website.com/w4w4wbvert9rtr/video.mp4
http://www.website.com/wserteg444gs4r/video.mp4
http://www.website.com/9we75y49wc45gr/video.mp4
http://www.website.com/sfwetb456/video.mp4

So I am wondering if there is a way that I can extract the text line by line and insert in into wget so I would just have to run wget and then a variable.

edit:

I used G Trawo's answer but made a small adjustment. I set it up to download all of the files at the same time by using gnome-terminal -e "wget $line" instead of just wget $line

Thanks,

Zimbinskers

  • 2
    It's straightforward using the bash shell's builtin read command: however, wget already has an option (-i file or --input-file=file) to read a list of URLs from a file, no? – steeldriver Dec 19 '15 at 1:12
3

The comment above already mentions that wget has the --input-file=file switch. If you want to do it with a script, follow below. Taken from here.

Fill a file named listofurls.txt with all your URLs.

Create a file called wget_readfile.sh

nano wget_readfile.sh

Paste this into it:

#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
wget $line
done < "$1"

Make it executable:

chmod +x wget_readfile.sh

Run it

./wget_readfile.sh listofurls.txt
|improve this answer|||||
  • Thanks! That helped out a lot but just so you know their is an extra ' at the end of your code, I removed the extra apostrophe and it worked! – user483937 Dec 19 '15 at 3:58

Your Answer

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