D
D
DimiDr0lik2017-08-25 21:49:09
linux
DimiDr0lik, 2017-08-25 21:49:09

How to download files using links from a table?

Good people, please help with a bash script,
there is a table with a full name and a link to a photo, how to download a photo and rename it to a full name?
I need it urgently, but I can’t figure it out on Friday already)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2017-08-25
@DimiDr0lik

#!/bin/bash

set -e

FOLDER="photos"

mkdir -p $FOLDER

function download () {
  local url=$1
  local name=$2
  filename=$(basename "$url")
  extension="${filename##*.}"
  wget -O"${FOLDER}/${name}.${extension}" "${url}"
}

while read line
do
  name=$(echo $line | awk -F  ";" ' {print $1} ' | sed -e "s/\ /_/g")
  url=$(echo $line | awk -F  ";" ' {print $2} ')
  download "${url}" "${name}"
done < $1

Run: Create a photos
folder and download photos there Example table.csv file :
Ярков Алексей Николаевич;https://avatars2.githubusercontent.com/u/6022892?v=4&s=460
Иванов Иван Иванович;https://avatars2.githubusercontent.com/u/23380632?v=4&s=460

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question