Upload files using bash script using wget

I am trying to create a simple script that will take a list of files that will be downloaded from a TXT file, and then, using a loop, it will read .txt which files should be downloaded using another split .txt file, where in the address of the files where it will be downloaded . But my problem is that I do not know how to do this. I tried many times, but I always failed.

file.txt
1.jpg
2.jpg
3.jpg
4.mp3
5.mp4

=======================================

url.txt
url = https://google.com.ph/

=======================================

download.sh
#!/bin/sh
url=$(awk -F = '{print $2}' url.txt)
for i in $(cat file.txt);
do 
wget $url
done

Your help is greatly appreciated.

+4
source share
2 answers

Instead

wget $url

Try

wget "${url}${i}"
+5
source

Besides the obvious problem that R Sahu mentioned in his answer, you can avoid:

  • awk url.txt.
  • for $(cat file.txt) file.txt.

:

#!/bin/bash

# Create an array files that contains list of filenames
files=($(< file.txt))

# Read through the url.txt file and execute wget command for every filename
while IFS='=| ' read -r param uri; do 
    for file in "${files[@]}"; do 
        wget "${uri}${file}"
    done
done < url.txt
+6

Source: https://habr.com/ru/post/1539205/


All Articles