marc:linux:bash_snippets
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| marc:linux:bash_snippets [2023/02/15 11:19] – [Remove duplicate and empty lines from file] marcv | marc:linux:bash_snippets [2023/02/16 14:23] (current) – [Download files based on URLs in a file] marcv | ||
|---|---|---|---|
| Line 251: | Line 251: | ||
| # download file using wget | # download file using wget | ||
| wget " | wget " | ||
| + | done < url.txt | ||
| + | </ | ||
| + | |||
| + | Do the same but check if file exists. If it does compare sizes and ask what to do. | ||
| + | |||
| + | < | ||
| + | |||
| + | # Read URLs from the url.txt file and download the files | ||
| + | while read url; do | ||
| + | filename=$(basename " | ||
| + | if [ -e " | ||
| + | local_size=$(wc -c <" | ||
| + | remote_size=$(curl -sI " | ||
| + | if [ " | ||
| + | echo " | ||
| + | continue | ||
| + | else | ||
| + | read -p "A file with the name $filename already exists. Do you want to save the new file with a different name? (y/n) " response | ||
| + | if [ " | ||
| + | read -p "Enter the new file name: " new_filename | ||
| + | curl -L -o " | ||
| + | echo "File saved as $new_filename." | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | fi | ||
| + | else | ||
| + | curl -L -o " | ||
| + | echo " | ||
| + | fi | ||
| done < url.txt | done < url.txt | ||
| </ | </ | ||
marc/linux/bash_snippets.1676456363.txt.gz · Last modified: (external edit)
