Run wget command on each line of a file and download the files (two at a time)

I have a file which has urls of files to download.

For example:


The command i am currently using to download files is:

wget --continue --tries=0 https://url-of/

But now I need a bash script which will read urls from the file and download, two at a time.

The script i came up with so far is:


cat file.txt |while read url
    wget --continue --tries=0 "$url"

But it download single file.

How can i edit it so that it download two files at a time.

Asked By: Ahmad Ismail


You can put multiple read commands in the while loop. For "two at a time", but them both in the background and then wait for them to complete

while read -r first && read -r second; do
    wget "$first" &
    wget "$second" &
done < input.file

But @muru’s comment is preferable.

Answered By: glenn jackman
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.