Skip to content

Instantly share code, notes, and snippets.

@cosmoscalibur
Last active December 17, 2019 01:43
Show Gist options
  • Save cosmoscalibur/16e77e0995f4416fc09b7944ac53e064 to your computer and use it in GitHub Desktop.
Save cosmoscalibur/16e77e0995f4416fc09b7944ac53e064 to your computer and use it in GitHub Desktop.
Download files from URL specified in plain text files (one per file) and save with the same name of the origin file. https://askubuntu.com/questions/1196228/wget-from-file-and-save-as-acording-to-file-name
#! /usr/bin/env bash
# usage: bash wget_custom.sh
# Put this file in the same directory of `frm` files with unique URL to download.
# Downloades file has the same name of `frm` file but the extension is `txt`.
# Answer to AskUbuntu question: https://askubuntu.com/questions/1196228/wget-from-file-and-save-as-acording-to-file-name
SAVEIFS=$IFS
IFS=$'\n'
files=$(ls -1 *.frm)
for file in ${files[@]}; do
downloaded_file=$(echo $file | sed 's/\.frm/.txt/')
url_file=$(more $file)
wget $url_file -O $downloaded_file
done
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment