Answer the question
In order to leave comments, you need to log in
How to run wget with data from two arrays?
There is a file ./result/ok.txt
1321231321321321321
4564654654564654654
4654654654654654564
http://url.ru/some?v=86ff8d97yguifidgijdhfkjghdflkgjdf
http://url.ru/some?v=879874g65df4g65d4gf65d4f65g4
http://url.ru/some?v=d89f7g98df7g987fd98g7d98f7gfd
wget -O ./img/1321231321321321321.jpg http://url.ru/some?v=86ff8d97yguifidgijdhfkjghdflkgjdf
wget -O ./img/4564654654564654654.jpg http://url.ru/some?v=879874g65df4g65d4gf65d4f65g4
wget -O ./img/4654654654654654564.jpg http://url.ru/some?v=d89f7g98df7g987fd98g7d98f7gfd
#!/bin/bash
declare -a NAMES
declare -a URLS
# Считываем файлы в массивы
NAMES=`cat ./result/ok.txt`
URLS=`cat ./result/urls.txt`
# Определяем длину массивов
LEN_NAMES=${#NAMES[@]}
LEN_URLS=${#URLS[@]}
# Папка для сохранения
IMG_FOLDER="img"
[ -d ${IMG_FOLDER} ] || mkdir -p ${IMG_FOLDER}
n=1
echo ${NAMES[$n]}
echo ${URLS[$n]}
#wget -b -O "./imgs/"$NAMES[$n]".jpg" $URLS[$n]
#for n in $LEN_NAMES
#do
#echo -n $fname
#wget -b -O "./imgs/"${NAMES[$n]}".jpg" ${URLS[$n]}
#done
Answer the question
In order to leave comments, you need to log in
makeun.sh
#!/bin/bash
read_lines_pair()
{
echo "$(head -$1 $2 | tail -1) $(head -$1 $3 | tail -1)"
}
convert_line()
{
sed 's/^/wget /; s%[^ ]*$%-O ./img/&.jpg%'
}
process()
{
local len=$(wc -l urls.txt | cut -d' ' -f1)
for i in `seq 1 $len`; do
read_lines_pair $i urls.txt names.txt | convert_line
done
}
process
[[email protected] makeun]$ ./makeun.sh
wget http://url.ru/some?v=86ff8d97yguifidgijdhfkjghdflkgjdf -O ./img/1321231321321321321.jpg
wget http://url.ru/some?v=879874g65df4g65d4gf65d4f65g4 -O ./img/4564654654564654654.jpg
wget http://url.ru/some?v=d89f7g98df7g987fd98g7d98f7gfd -O ./img/4654654654654654564.jpg
[[email protected] makeun]$
./makeun.sh | sh
It seems like cat considered the entire file as 0 array element, and not line by line.
line by line you can do this:
# Считываем файлы в массивы
NAMES=()
while read -r LINE; do
NAMES+=("$LINE")
done < 'ok.txt'
URLS=()
while read -r LINE; do
URLS+=("$LINE")
done < 'urls.txt'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question