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


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.


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



  • 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

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:

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
