0

I would like to download files from a list. e.g. list.txt is the list file. It contains the list of file names:

pic_01.jpg
pic_02.jpg
pic_xxx.jpg

I need a loop which takes out the file name one by one and write it into an another file (just one name). The download script will use this single file name.

To summarize: send a file name from a list to another file, which contains only one file name (probably with a loop).

dessert
  • 39,982
  • Not sure if it helps, but if you have a list of urls in your file, you can use wget to download them all in one go. https://askubuntu.com/questions/103623/download-files-from-a-list – Dan Apr 09 '18 at 07:30

1 Answers1

1

You can read the file line by line with a while loop and echo each one to a new file:

#!/bin/bash
while IFS='' read -r l || [[ -n "$l" ]]; do
    echo $l >$(mktemp -p.)
done <list.txt

This will loop over every line of list.txt and print the whole line to a tempfile created in the current directory. By default mktemp uses the template tmp.XXXXXXXXXX to create the files – the Xs are replaced by random characters – you can adapt that to your needs by specifying a different template, e.g. making it mktemp -p. file.XXXXX.

Further reading:

dessert
  • 39,982