0

I have a bash script that scrapes a list of urls for links to various kinds of documents. At the end, the script uses wget to download the files. However, I'm having trouble with filenames containing white space in the name: wget ends the url at the space. Is there some way to use sed or something to change the white space to %20 here? Or some other solution? This is my code:

for url in $(cat download.md)
do
    lynx --listonly --dump $url | \
awk '/\.(pdf|doc|docx|odt)$/{ sub("^[ ]*[0-9]+.[ ]*","",$0); print}'

done > ~/links.txt

for i in $( cat ~/links.txt ); do wget $i; 
done
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Linter
  • 159

1 Answers1

1

You lost the full filenames during the $( ... ) command substitution. Just ask wget to read the file directly:

wget -i ~/links.txt
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255